I used to use ASP.NET update panel control to do Ajax. I've heard that using JQuery would be a better way to make Ajax call, so I am wondering what are some of the most popular ways to make Ajax call with JQuery? Example(s) or links to tutorials would be greatly appreciated!
Asked
Active
Viewed 57 times
-2
-
See http://api.jquery.com/category/ajax/ or http://api.jquery.com/jQuery.ajax/ – Paul Jul 31 '13 at 03:20
3 Answers
0
There are many ways depending on your needs, but a common one is
$.get('/yoururl',{inputParam:someVal},function(data){
//do whatever with the returned data
});
TGH
- 38,769
- 12
- 102
- 135
0
One simple way is using web methods:
jQuery AJAX call to an ASP.NET WebMethod
http://deebujacob.blogspot.ca/2012/01/aspnet-ajax-web-method-call-using.html
For example in your aspx.cs:
[WebMethod()]
public static string GetData(int userid)
{
/*You can do database operations here if required*/
return "my userid is" + userid.ToString();
}
in your aspx:
function asyncServerCall(userid) {
jQuery.ajax({
url: 'WebForm1.aspx/GetData',
type: "POST",
data: "{'userid':" + userid + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert(data.d);
}
});
}
0
This is definitely the best page / website to look at.
http://api.jquery.com/jQuery.ajax/
or if you want
http://www.w3schools.com/jquery/jquery_ref_ajax.asp
$.ajax({
url : "page.asp",
data : {
"param1" : 1,
"param2" : "Hello World" //you can access these with the server's request object
},
type : "GET", //or post
cache : true, //use your cache? (only applies to certain types)
dataType : "json", //what kind of data are you expecting? (or Intelligent guess)
success : function(message) { //message depends on dataType
console.log(message);
},
error : function() {
console.log(arguments);
}
});
Logan Murphy
- 6,120
- 3
- 24
- 42