admin管理员组文章数量:1278655
My page contains the following code in the function called when a button is clicked:
$.ajax({
type: "POST",
url: "ProviderPortal.aspx/ppTransferToProvider",
data: "{ICA_Key:'" + ICAKey + "', PROV_Key:'" + Provider + "'}",
contentType: "application/json; charset=utf-8",
async: true,
cache: false,
dataType: "json",
success: function(msg) {
alert(msg)
}
});
This code is modeled after the selected answer to Calling an ASP.NET server side method via jQuery
However, I'm not sure if the ASP.NET (VB, Net 2.0) function signature
<WebMethod()> _
Public Shared Function ppTransferToProvider( _
ByVal ICA_Key As String, _
ByVal Prov_Key as String) As String
on the page will receive the data as distinct parameters, or as a string that will have to be parsed for these values. Also, I can't determine if the call is even being made correctly; it seems that a breakpoint in the function itself is never getting hit, so I can't see it for myself.
a) Are parameters passed as just a big string, or are they correctly passed to my function with two parameters? b) How can I trace the execution of the ASP.NET function? Or is it possible to trace, given that it's shared?
My page contains the following code in the function called when a button is clicked:
$.ajax({
type: "POST",
url: "ProviderPortal.aspx/ppTransferToProvider",
data: "{ICA_Key:'" + ICAKey + "', PROV_Key:'" + Provider + "'}",
contentType: "application/json; charset=utf-8",
async: true,
cache: false,
dataType: "json",
success: function(msg) {
alert(msg)
}
});
This code is modeled after the selected answer to Calling an ASP.NET server side method via jQuery
However, I'm not sure if the ASP.NET (VB, Net 2.0) function signature
<WebMethod()> _
Public Shared Function ppTransferToProvider( _
ByVal ICA_Key As String, _
ByVal Prov_Key as String) As String
on the page will receive the data as distinct parameters, or as a string that will have to be parsed for these values. Also, I can't determine if the call is even being made correctly; it seems that a breakpoint in the function itself is never getting hit, so I can't see it for myself.
a) Are parameters passed as just a big string, or are they correctly passed to my function with two parameters? b) How can I trace the execution of the ASP.NET function? Or is it possible to trace, given that it's shared?
Share Improve this question edited May 23, 2017 at 11:50 CommunityBot 11 silver badge asked Nov 3, 2011 at 16:34 taseriantaserian 6237 silver badges19 bronze badges3 Answers
Reset to default 6The problem is you're passing a string
while you're service is expecting a set of objects. Try the following instead
data: {ICA_Key: ICAKey, PROV_Key: Provider },
If you are going to pass objects, bite the bullet and use JSON2.stringify
. You can then work with js object and now worry about string manipulation, quotes, parsing..etc:
var exmapleParams = {ICA_Key: ICAKey, PROV_Key: Provider };
$.ajax({
type: "POST",
url: "ProviderPortal.asmx/ppTransferToProvider",
data: JSON2.stringify(exmapleParams),
contentType: "application/json; charset=utf-8",
async: true,
cache: false,
dataType: "json",
success: function(msg) { //ms web services return .d
alert(msg.d)
}
});
<WebMethod()> _
Public Shared Function ppTransferToProvider( _
ByVal exmapleParams As CustomObject) As String
However, I'm not sure if the ASP.NET (VB, Net 2.0) function signature [...] on the page will receive the data as distinct parameters, or as a string that will have to be parsed for these values
You'll get distinct values. Your data
property in your $.ajax
call may need to be changed from:
data: "{ICA_Key:'" + ICAKey + "', PROV_Key:'" + Provider + "'}",
to:
data: "{ICA_Key:'" + ICAKey + "', Prov_Key:'" + Provider + "'}",
I say may only because I don't know if VB.NET is case sensitive in this regard, but C# does require the case of the JavaScript object's property to exactly match the parameter in the AJAX WebMethod.
Note that your VB function expects variables named ICA_Key
and Prov_Key
. If the name PROV_Key
is correct, then you likely need to rename your VB parameter to match what you're passing.
b) How can I trace the execution of the ASP.NET function? Or is it possible to trace, given that it's shared?
You can trace the execution of your WebMethod, but you do need to remove the shared
keyword (From my understanding, shared
in VB is equivalent to static
in C#, so my answer is based off that).
Hope this helps.
本文标签: javascriptCalling ASPNET function using JQuery AJAX callStack Overflow
版权声明:本文标题:javascript - Calling ASP.NET function using JQuery $.AJAX call - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741216992a2360236.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论