Considerations for the definition of Ajax cross-domain value JSONP

Source: Internet
Author: User

Today to do a go before the project to fetch data, intended to build an interface, WebServer. Encountered some problems in the middle. Is the problem of cross-domain value

Client page

1. First AJAX request Dataty: ' JSONP ' This format, but also add a JSONP: "Callback", the most important thing is that there is a callback function callback (), you can toss me bad. Directly on the client code:

<script type="Text/javascript">$ (function () {$.ajax ({type:"GET", URL:"Http://localhost:48748/WebService1.asmx/GetGrid", Data:"", DataType:"Jsonp", Jsonp:"Callback", Success:function (data) {callback (data);                }, Error:function (Error) {Console.log (error); })}) function callback (data) {alert (data.rows[0].             Name); }    </script>

Background code.

2. Using the webserver server, the specific configuration is not much to say, today's topic is the cross-domain access to JSON data, the need to pay attention to the problem is mentioned earlier, need to use a callback callback function, to have a certain format. Please look at the code:

[WebMethod] Public voidGetgrid () {List<Notice> list =NewList<notice>(); List. ADD (NewNotice {id=1, name="xiaoming"}); JavaScriptSerializer JSON=NewJavaScriptSerializer (); varGrid =New{rows =list}; Context.Response.Write ("Callback ("+json. Serialize (GRID) +")"); }

This thing has been going on for a day, written on: January 27, 2015 01:06:09

Considerations for the definition of Ajax cross-domain value JSONP

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.