what is the right syntax for a JSON encoded PUT request using jQuery AJAX
15,579
This is what I do. Hope it helps:
var WebServiceUrl = 'SomeWebservice.asmx/SomeMethod';
var DataToSend = new Object();
DataToSend = {
FirstName : 'John',
LastName : 'Smith'
};
//Call jQuery ajax
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: WebServiceUrl,
data: JSON.stringify(DataToSend),
dataType: "json",
success: function (msg) {
alert('Success');
},
error: function (err){
alert('Error');
}
});
And assuming you have a Webservice. I have a simple ASP.NET VB web service: SomeWebservice.asmx and its method signature as follows:
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function SomeMethod(ByVal FirstName As String, ByVal LastName As String) As String
Author by
Dave-88
Updated on June 08, 2022Comments
-
Dave-88 almost 2 years
I write my ajax PUT request:
jQuery.ajax({ url: url_lab_data+"backend/read/{\"f_anid\":"+anid+"}", type: "PUT", data: JSON.stringify({"read": 1}), contentType: "application/json", success: function (data) { } });
But I get an OPTION Method in the Network log in Chrome. Why?
Is the Syntax not correct?
I hope someone can help me.