Using jquery's ajax approach for cross-domain access

Source: Internet
Author: User

The front page test code is as follows:

<!DOCTYPE HTML><HTML><Head>    <styletype= "Text/css">. Gridtable{font-family:Verdana,arial,sans-serif;font-size:11px;Color:#333333;Border-width:1px;Border-color:#666666;Border-collapse:collapse;}     </style><Scriptsrc= "Http://code.jquery.com/jquery-1.10.2.min.js"></Script><Script>        functionTestajax () {varname= $("#username"). Val (); $.ajax ({type:"Post", URL:"xxxxxxxxxx",//URLs that are properly accesseddata: {name:name}, DataType:"Jsonp", Jsonp:"Jsonpcallback",//Jsonp This property can be used without the specific application of this property to be developedSuccess:function(data) {}}); }        functionjsonpcallback (Result)//the method name should be the same as the method name written to response in the background    {        varcallbackmsg=result.msg; if(callbackmsg== "OK") {alert ("Test success!"); $("#form"). Submit (); }        Else{alert (callbackmsg); }    }    </Script></Head><Body><DivAlign= "Center"><H1>Test</H1><formAction=""ID= "form">    <Tableclass= "Gridtable">        <TR><TD>Name</TD><TD><inputtype= "text"ID= "username" /></TD></TR>        <TR><TD><inputtype= "button"value= "CONFIRM"onclick= "Testajax ();"/></TD></TR>    </Table></form></Div></Body></HTML>

The appropriate test code for the server side is as follows:

function Test (Request, response) {    var name = Request.getparameter ("name");     if (name = = "Test")    {        Response.Write ("Jsonpcallback ({msg: ' OK '})"); // method name Jsonpcallback, but the method name of the foreground to return the value should be the same name     }    else    {        var errmsg = "error Test";        Response.Write ("Jsonpcallback ({msg: '" + errmsg + "'})"); // method name Jsonpcallback, but the method name of the foreground to return the value should be the same name     }}

Using jquery's ajax approach for cross-domain access

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.