JQuery Ajax invokes some of the experience records of WebService, in this case, resolving cross-domain use of the core solution, in the next article, will introduce the problem of JS Cross-domain. Instance. Instance. Instance. Cross-domain Solution instance-source front-end
function Sendpost () {
$.ajax ({
' url ': ' Http://100.80.62.40:8080/WebService.asmx/HelloWorld ', '
type ': ' POST ',
' contentType ': "Application/json;" Charset=utf-8 ",
' data ': ',
' dataType ': ' json ',
' success ': function (response) {
Console.log ( Response);
Console.log (RESPONSE.D);
Console.log (Json.parse (RESPONSE.D));
}
);
There is still a small problem here, by the way introduction. So about Json.parse parsing, in fact this is a small problem, the correct format for JSON is: {"result": "Success"}, note that the content must be double quotes, cannot be single quotes, the single quotation mark will appear so wrong. So in the Webservic method for the correct use of JSON format, use double quotes to escape.
, WebService
[WebMethod]
public string HelloWorld ()
{return
"{\ result\": \ "Success\"} ";
}
Web.config
System.Web, pay attention to the writing of webservice and its sub tags
<system.web>
<compilation targetframework= "4.5.2" debug= "true"/>
The second part, this piece is to solve the JS source strategy, Cross-domain problem. Allow non-homology calls
<system.webServer> <!--resolving Cross-domain requests by Wys-->