I have come a very weird problem . Here it goes.
I am using a knockout js application speaking to webapi controller and service layers and so on.
I have kendo grid , in that after editing a row ,calling an event in the page , and within the event making an ajax call to send data to webapi controller.
Now the interesting thing is when I put breakpoint in .js file and put F12 , the control is coming to the controller otherwise it is just skipping away. Not sure what is happening at all.
the ajax code is:
$.ajax({
url:controller,
type:"PUT",
data:"em",
datatype:'json',
success:function(result){
}
});
[HttpPut]
[OdataRoute("PutDataController")]
public async Taask<string> PutDataController(HttpRequestMessage par)
{
//Do something
}
I tried giving 'async' : false also, but it dint work
You should add an error function to that ajax call, so you can get access to the exception.
var form = $("#form");
var data = form.serialize();
$.ajax({
url: form.attr('action'),
type: form.attr('method'),
data: data,
dataType: "json",
success: function (message) {
alert("GREAT!");
},
error: function (xhr, status, error) {
alert("Error: " + xhr.responseText);
}
});
Try to set the data as an object and not as a string:
$.ajax({
url:controller,
type:"PUT",
data: {myvar: "em"},
datatype:'json',
success:function(result){}
});
Use data: {myvar: "em"}
instead of data:"em"
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.