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.

hyprstack
  • 4,043
  • 6
  • 46
  • 89
  • use $.ajax() as it is a more pwerfull wrapper and get is only a shorthand for $.ajax() GET request – john Smith Sep 10 '14 at 11:09
  • possible duplicate of [jQuery AJAX submit form](http://stackoverflow.com/questions/1960240/jquery-ajax-submit-form) – Teo Sep 10 '14 at 12:09

2 Answers2

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()

Community
  • 1
  • 1
Hamix
  • 1,323
  • 7
  • 18
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)
}
iMichaeln
  • 46
  • 3