0

I am trying to use ajax and jQuery to send the data submitted in a form to the server and retrieve the response form the server and serve it up on the webpage again. What method should I be using do accomplish this?

I am not sure if I should use $.get() or $.ajax() or if I should be using any other of the methods on the jQuery API. Could someone please shed some light on this question? Thanks.

2
  • use $.ajax() as it is a more pwerfull wrapper and get is only a shorthand for $.ajax() GET request Commented Sep 10, 2014 at 11:09
  • possible duplicate of jQuery AJAX submit form Commented Sep 10, 2014 at 12:09

2 Answers 2

1

A nice and simple tutorial for you
Call ASP.Net Page Method using jQuery AJAX Example

See also
Difference between $.ajax() and $.get() and $.load()

Sign up to request clarification or add additional context in comments.

Comments

0

hope that can help you:

jquery and ajax request:

$("#submitButton").on("click", function () {
  $("#formid").submit(submitForm());
  return false;
});
var submitForm = function() {
    $.ajax({
        type: "POST",
        dataType: "json",
        data: $("#formid").serialize(),
        url: '@Url.Action("function","controller")',
        success: function (data) {
             alert(data);
        }
    });
});

server side:

[HttpPost]
public JsonResult Function(SubmitViewModel viewModel)
    return Json("response from the server is here", "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet)
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.