response.contenttype

Can I return JSON from an .asmx Web Service if the ContentType is not JSON?

我只是一个虾纸丫 提交于 2019-12-17 06:14:43
问题 I would like to post a form using ajax and jquery to a .asmx webservice and return the value from the webservice as JSON. I'm using ASP.NET 4.0. I know that in order to return JSON from a webservice the following needs to be set (1) dataType: "json" (2) contentType: "application/json; charset=utf-8", (3) type: "POST" (4) set the Data to something. I have tested this and it works fine (i.e. my webservice returns the data as JSON) if all **four are set**. But, lets say in my case I want to do a

Can I return JSON from an .asmx Web Service if the ContentType is not JSON?

旧巷老猫 提交于 2019-11-26 22:56:45
I would like to post a form using ajax and jquery to a .asmx webservice and return the value from the webservice as JSON. I'm using ASP.NET 4.0. I know that in order to return JSON from a webservice the following needs to be set (1) dataType: "json" (2) contentType: "application/json; charset=utf-8", (3) type: "POST" (4) set the Data to something. I have tested this and it works fine (i.e. my webservice returns the data as JSON) if all **four are set**. But, lets say in my case I want to do a standard form post i.e. test1=value1&test2=value2 so the contentType is not JSON but I want back JSON