JQuery Ajax Call WebService instance detailed _web

Source: Internet
Author: User

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--> 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.