jquery-php cross-domain Request data

Source: Internet
Author: User

Jquery:

1 //Get domain name2 functiongetdomain (URL) {3     varA = document.createelement (' A ');4A.href =URL;5Url=A.hostname;6     returnURL;7 }8 9 //Record VisitorsTen functionRecordvisitor () { One     varREFERRERMZ =Escape (GetDomain (Document.referrer)); A     varHREFMZ =Escape (GetDomain (window.location.href)); -sendinfo= "judgemz=413322&referrermz=" +escape (REFERRERMZ) + "&hrefmz=" +Escape (HREFMZ); - $.ajax ({ theType: "Get",  -Asynctrue,  -URL: "http://www.mazey.net/config/api/record-receive.php",  -data:{judgemz:413322, REFERRERMZ:REFERRERMZ,HREFMZ:HREFMZ}, +DataType: "Jsonp",  -JSONP: "Callback", +Jsonpcallback: "Returnfun", ASuccessfunction(data) { atMyarr=data.split ("-|-") -             if("0507" ==myarr[0]){ -Console.log (myarr[1]); -}Else if("0215" ==myarr[0]){ -Console.log (myarr[1]); -             } in         },  -Errorfunction(){  toConsole.log ("Server error!"); +         }  -     }); the } *  $ //LoadingPanax Notoginseng$ (document). Ready (function () {  - recordvisitor (); the});

Php:

1<?PHP2 require‘.. /config.php ';3 $judgeMz=$_get["Judgemz"];//TODO follow up to do a verification not 413322 error4 $referrerMz=$_get["Referrermz"];5 $hrefMz=$_get["HREFMZ"];6 $visitorIP=GetIP ();7 8 $data= Returnfun ($referrerMz,$hrefMz,$visitorIP); 9 Exit($_get[' Callback ']. ' ('. Json_encode ($data) . ‘)‘); Ten  One functionReturnfun ($referrerMz,$hrefMz,$visitorIP) {  A     $urlRecordVisitor= ' http://www.mazey.cn/config/config-asp/api/record-receive.asp?referrerMz= '.$referrerMz.‘ &hrefmz= '.$hrefMz.‘ &visitorip= '.$visitorIP; -     $resultMz=file_get_contents($urlRecordVisitor); -     return $resultMz; the } -?>

Other:

Because Http://www.mazey.cn/config/config-asp/api/record-receive.asp is at home, it seems to be a bit slow to visit. Ready to follow the ASP rewrite PHP back-end write code, originally planned a lot of things, other things this step to finish later.

jquery-php cross-domain Request data

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.