jquery Ajax Jsonp Calling instance code across domains

Source: Internet
Author: User
Tags json

  Today studied the way Ajax uses JSONP to make Cross-domain calls, finding that you can make cross-domain calls using Get and post methods, and here's a simple sharing, easy to use friend

The client code     code is as follows: <%@ Page language= "C #" autoeventwireup= "true" codebehind= "WebForm1.aspx.cs" inherits= " Webapp.webform1 "%> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <html xmlns=" http://www.w3.org/1999/xhtml "> <head runat=" Server "> <script src=" Jquery-1.7.1.min.js "type=" Text/javascript "></script> <script type=" Text/javascript ">     function aa () {        $.ajax ({            URL: "http://localhost:1207 9/webform2.aspx ",             data:" p1=1&p2=2&callback= ",       &NB Sp     Type: "Post",             Processdata:false,         &NBS P   timeout:15000           DataType: "Jsonp",  //not "json" we ' ll parse             JSONP: "Jsonpcallback"             success:function (result) {            alert (result.value1);            }        }    }   </script>     <title></title> </head> <body>     <form id= "Form1" runat= "Server" >     <div>       </div>     </for m>     <p>       <input   id= "Button1" type= "button" value= "button" onclick= "AA ( ) "/></p> </body> </html>     server-side code     code is as follows:  public partial class WebForm 2:system.web.ui.page     {        protected void Page_Load (object sender, EventArgs e) &n Bsp       {                       string callback = request["Callback"];              string v1= "1";             string v2= "2";             String response = "{value1": "" + v1 + "", "value2": "+ V2 +" "}";             String call = Callback + "(" + Response + ")";             Response.Write (call);             Response.End ();        }     {    client page and server-side page in two projects for Cross-domain call testing.   Cross-domain instance code (need to load jquery, page for UTF-8 encoding):     Code as follows:  <!--pull Hook recruitment data-->   <script type= "text/ JavaScript ">    function success_jsonpcallback (data) {    var html = ';     var pos = ' ;     HTML + + ' <ul> ';     Jquery.each (data, function (k, v) {                 if (K<10) {                  pos = ' "' + v.city+ ' "' + V.positionname + ' (' + v.salary + ')-' +v.companyname;       if (Pos.length >) {       pos = pos.substring (0,19) + ' ... ';     &NB Sp               &nbsp                   &N Bsp  html + = ' <li><a href= ' +v.posiitondetailurl+ ' target= ' _blank ' title= ' "' + v.city+ '" ' + V.positionName + ' (' + v.salary + ')-' +v.companyname+ ' "> ' +pos+ ' </a></li> ';                  }    };     HTML + + ' </ul><div class= ' more-link ' ><a href= ' http://www.lagou.com/jobs/list_%E5%89%8D% e7%ab%af%e5%bc%80%e5%8f%91 "target=" _blank "> More </a></div>";     jQuery (' #lagouData '). HTML (HTML);   &nbsp      function Getlagoudata () {    Jquery.ajax ({     async:false,      url: "Http://www.lagOu.com/join/listw3cplus?kd=%e5%89%8d%e7%ab%af%e5%bc%80%e5%8f%91 ",      type:" Get ",      datatype: "Jsonp",      jsonpcallback: ' Success_jsonpcallback ',      contenttype: " APPLICATION/JSONP; Charset=utf-8 ",      success:function (data) {      success_jsonpcallback (data);   &N Bsp &NBSP}    });   &nbsp    getlagoudata ();         </script>       <div id= "Lagoudata" ></div>     JSON P Code:     Copy code code as follows: Success_jsonpcallback ([{"City": "Guangzhou", "CompanyName": "POCO.") CN "," Createtime ":" 15:02 release "," Posiitondetailurl ":" http://www.lagou.com:80/jobs/16868.html "," Positionadvantage ":" In a cohesive team, the old City to work convenient transportation, double Hugh, "Positionname": "Commercial Front-End Development Engineer", "salary": "4k-7k"},{"City": "Beijing", "CompanyName": "Mei Tong Yun-Move (Beijing) Technology Co., Ltd." , "Createtime": "14:47 release", "Posiitondetailurl": "http://www.lagou.com:80/jobs/16866.html", "Positionadvantage": " HTML5 Technology's best team "," PosItionname ":" "Web Front-End Development", "salary": "4k-8k"},{"City": "Hangzhou", "CompanyName": "Pocket shopping", "Createtime": "14:42 release", " Posiitondetailurl ":" http://www.lagou.com:80/jobs/13024.html "," Positionadvantage ":" a broad platform for development, the embodiment of self-worth "," Positionname ":" "Web front-end Development Engineer", "salary": "8k-12k"},{"City": "Beijing", "companyName": "Pudding Move", "Createtime": "14:02 release", " Posiitondetailurl ":" http://www.lagou.com:80/jobs/1498.html "," positionadvantage ":" Meals, surrounded by beautiful like clouds "," positionname ":" Android Development Engineer, "salary": "10k-20k"},{"City": "Beijing", "companyName": "Pudding Move", "Createtime": "14:02 release", "Posiitondetailurl" : "Http://www.lagou.com:80/jobs/2539.html", "positionadvantage": "Meals, small bridges, beautiful women", "Positionname": "iOS Development Engineer", "salary ":" "10k-20k"},{"City": "Shanghai", "CompanyName": "Beautiful every Day", "Createtime": "00:55 release", "Posiitondetailurl": "http:// Www.lagou.com:80/jobs/11494.html "," positionadvantage ":" Entrepreneurial atmosphere to emphasize small and beautiful "," Positionname ":" Android Development engineer "," Salary ":" 8k-16k "},{" City ":" Beijing "," CompanyName ":" Lbe Security Master "," Createtime ":" 11:39 release "," Posiitondetailurl ":" Http://www.lagou.com : 80/jobs/5983.html "," Positionadvantage ":" Five insurance and one gold performance bonus "," pOsitionname ":" Android Development engineer "," salary ":" 8k above "},{" City ":" Beijing "," companyName ":" Dim sum Move "," Createtime ":" 11:24 release "," Posiitondetailurl ":" http://www.lagou.com:80/jobs/16736.html "," Positionadvantage ":" Technology-oriented team atmosphere, a full range of welfare benefits "," Positionname ":" "Android", "Salary": "15k-25k"},{"City": "Guangzhou", "CompanyName": "Litchi FM", "Createtime": "10:44 release", " Posiitondetailurl ":" http://www.lagou.com:80/jobs/16634.html "," positionadvantage ":" Even insist on running, to maintain the weight of the reward Oh! "," Positionname ":" WP mobile phone development engineer "," salary ":" 16k-25k "},{" City ":" Beijing "," companyName ":" NET silver-Jingdong subsidiary "," Createtime ":" 10:08 release ", "Posiitondetailurl": "http://www.lagou.com:80/jobs/14162.html", "Positionadvantage": "in charge of Jingdong Mall-Internet financial products JS development", " Positionname ": Javascript front-end Development engineer", "salary": "10k-20k"}])    
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.