jquery Ajax Jsonp Calling instance code across domains _jquery

Source: Internet
Author: User

Client code

Copy Code code 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 ">
<script src= "Jquery-1.7.1.min.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >
function aa () {
$.ajax ({
URL: "Http://localhost:12079/WebForm2.aspx",
Data: "P1=1&p2=2&callback=?",
Type: "Post",
Processdata:false,
timeout:15000,
DataType: "Jsonp",//Not "JSON" we ll parse
JSONP: "Jsonpcallback",
Success:function (Result) {
alert (result.value1);
}
});
}

</script>
<title></title>
<body>
<form id= "Form1" runat= "Server" >
<div>

</div>
</form>
<p>
<input id= "Button1" type= "button" value= "button" onclick= "AA ()"/></p>
</body>

Server-side code

Copy Code code as follows:

public partial class WebForm2:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{


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 ();
}
}

The client page and server-side pages are in two projects for Cross-domain call tests.

Cross-domain instance code (need to load jquery, page is utf-8 encoding):

Copy Code code as follows:

<!----> 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 > 20) {
pos = pos.substring (0,19) + ' ... ';
}
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);
}

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);
}
});
}
Getlagoudata ();
</script>
<div id= "Lagoudata" ></div>

JSONP 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 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, self-value embodiment of the place " , "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 bridge water people, beauty", "Positionname ":" iOS Development Engineer "," salary ":" 10k-20k "},{" City ":" Shanghai "," companyName ":" Every Day Beautiful "," Createtime ":" 00:55 release "," Posiitondetailurl ":" "http://www.lagou.com:80/jobs/11494.html", "positionadvantage": "Entrepreneurial atmosphere emphasizes 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 risks, 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

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.