Am I missing something? I’m trying to do a simple ajax call using jquery to a web service on my site and I get a 500 error every time when I make the call from the master page. Has no one ever made an ajax call from a master page or am I just crazy and extremely deprived of sleep?
Example:
MasterPage.master
<script type="text/javascript">
$(document).ready(function () {
$.ajaxSetup({ dataType: "json", contentType: "application/json; charset=utf-8" });
$.ajax({
url: '<%= ResolveUrl("~/Services/Test.asmx/HelloWorld") %>',
success: function (data) {
alert(data);
},
error: function (xhr, err) {
alert("readyState: " + xhr.readyState + "\nstatus: " + xhr.status);
alert("responseText: " + xhr.responseText);
}
});
});
</script>
/Services/Test.asmx
<WebMethod()> _
Public Function HelloWorld() As String
Return "Hello World"
End Function
See anything wrong? Do I have a misunderstanding of the Master Page? Please help!
Ok, I believe I have figured out the problem. Now I’m beginning to think I am just sleepy. A couple of issues that I had and I’ll list them for everyone else to make sure they DON’T do in the future:
1) I remember reading another post previously that explained that an ajax call via the jQuery library does not like a null object for data so something has to be listed even if it’s an empty array. So, that’s exactly what I added:
2) Once I got past the jQuery ajax problem, I was then presented an error message from the web service itself. Warned me that to be able to call the web service from a script, I have to add the following line:
This solved it and now I can call it wherever it resides. Thanks for the posts but looks like I was just overlooking things as usual…