我曾经使用ASP.NET更新面板控件来执行Ajax。我听说使用JQuery是一种更好的方式来进行Ajax调用,所以我想知道用JQuery调用Ajax的一些最流行的方法是什么?将非常感谢示例或教程链接!
答案 0 :(得分:0)
根据您的需求,有很多种方式,但常见的方法是
$.get('/yoururl',{inputParam:someVal},function(data){
//do whatever with the returned data
});
答案 1 :(得分:0)
一种简单的方法是使用Web方法:
jQuery AJAX call to an ASP.NET WebMethod
http://deebujacob.blogspot.ca/2012/01/aspnet-ajax-web-method-call-using.html
例如在你的aspx.cs中:
[WebMethod()] public static string GetData(int userid) { /*You can do database operations here if required*/ return "my userid is" + userid.ToString(); }你的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); } }); }
答案 2 :(得分:0)
这绝对是最好的页面/网站。
http://api.jquery.com/jQuery.ajax/
或者如果你想要
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);
}
});