jquery - How do you make an ASP.Net 3.5 WebService accept AJAX PUT requests? -


i not able webservice in asp.net 3.5 project accept put requests.

here ajax call:

var url = '/myservice.asmx/updateobject'; var options = {     datatype: "json",     contenttype: "application/json",     cache: false,     type: "put",     data: data ? ko.tojson(data) : null };  $.ajax(url, options); 

in myservice.asmx, have following:

[webmethod(enablesession = true)] [system.web.script.services.scriptmethod(responseformat = system.web.script.services.responseformat.json, usehttpget=true)] public butdto updateobject(objectdto myobject) {     //do stuff here      return myobject; }     

however, getting following error message:

an attempt made call method updateobject using post request, not allowed.

if remove ", usehttpget=true" web service declaration , perform same ajax call, getting following error message:

an attempt made call method updateobject using request, not allowed.

so bit baffled here.

update:

i tried datatype: "text", result same.

looking @ msdn, post , acceptable http verbs scriptmethod.

as why getting errors. if put json array data property when send ajax request, jquery serializes query string , sends server. that's not asp.net looking for. need pass jquery string of json want use. like:

var url = '/myservice.asmx/updateobject'; var options = {     datatype: "json",     contenttype: "application/json; charset=utf-8",  // add charset measure     cache: false,     type: "post",     data: "{'id':2, 'name':'foobar'}"  // notice quotes here };  $.ajax(url, options); 

you use json.stringify() json2 if want turn javascript object json string needed complete request.

if want read more take @ http://encosia.com/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/ has lot of information of common mistakes are.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -