jQuery的阿贾克斯get方法与参数没有在asp.net工作 [英] Jquery ajax get method with parameter is not working in asp.net
本文介绍了jQuery的阿贾克斯get方法与参数没有在asp.net工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想打电话给使用jQuery阿贾克斯获得method.but它是没有得到所谓的Web方法。我下面的JavaScript和code
I want to call a web method using jquery ajax get method.but it is not getting called. below my javascript and code
的javascript:
function RetrievePassword() {
var forgotEmail = $("#txtForgotEmail").val().trim();
//call the ajax method to retrieve the password from the email address provided.
$.ajax({
type: "GET",
url: "test.aspx/RetrievePassword?email=" + forgotEmail,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
alert(result.d);
},
error: function () {
alert("Error while calling the server!");
}
});
}
背后的功能我的code
[WebMethod]
[ScriptMethod(UseHttpGet=true)]
public static string RetrievePassword(string email)
{
//some code
}
任何人可以帮助我在此。
Can anybody help me on this..
推荐答案
有关安全方面的原因, ASP.Net AJAX
页面方法只支持 POST
请求。
For security reasons, ASP.Net AJAX
page methods only support POST
requests.
下面的例子是使用 POST
要求所示
Below example is shown using POST
request
的的jQuery 的
$.ajax({
type: "POST",
url: "test.aspx/RetrievePassword",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: '{email:"' + forgotEmail + '"}',
success: function (result) {
alert(result.d);
},
error: function () {
alert("Error while calling the server!");
}
});
C#PageMethod的
C# Pagemethod
[WebMethod]
public static void RetrievePassword(string email)
{
//some code
}
记住使用AJAX POST数据变量的名称作为PageMethod的的参数中使用。因为它的情况下,sesitive
Remember to use ajax post data variable name as used in pagemethod's argument. As it's case-sesitive
这篇关于jQuery的阿贾克斯get方法与参数没有在asp.net工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文