User1362505679 posted
Hi,
I have a web user control, i am trying to make an Ajax call to web service on hyperlink click event.
When I am trying to send parameters from AJAX call to web method, I always end up in getting the message : Parameter <name> is missing. Below is my ajax call.
$('a[href="#next"]').click(function () {
var obj = {};
obj.City = "Test City";
obj.State = "Test State";
$.ajax({
url: '<%=ResolveUrl("~/WebServices/Level1ExamSaveData.asmx/HelloWorld")%>',
data: JSON.stringify(obj),
type: "POST",
datatype: "JSON",
contenttype: "application/json; charset=utf-8",
async: true,
success: function (r) {
alert(r);
if (returnval == "City") {
alert("server side method called successfully");
}
},
error: function (xhr, ajaxoptions, thrownerror) {
alert('exception:'+thrownerror + "value: "+xhr.responseText);
}
}).done(function () {
$('#<%=txtcity.clientid%>').val('test modifed');
});
});
And Web method is this:
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function HelloWorld(ByVal City As String, ByVal State As String) As String
Return "City"
End Function
I have observed, the method gets called successfully if the web method doesn't have parameters (like below).
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function HelloWorld() As String
Return "Hello World"
End Function
I have checked the response on success, its a [object XMLElement], so I am assuming the AJAX call is made using XML not JSON. Please let me know if my assumption is right, and help me with a solution.
Regards,
Siva Karthik