Use jQuery to implement simpler Ajax cross-origin requests

Source: Internet
Author: User
Tags getscript
Author: Yang Guo from the bodhi tree Source: blog Park Release Date: Reading: 371 Original article links [favorites]

A while ago I sent an article using ExtJs ScriptTagProxy to implement Ajax cross-origin request (http://www.cnblogs.com/yjmyzz/archive/2008/09/14/1290789.html), these days I read Jquery, it is found that using getScript in JQuery is actually easier (jquery 1.2.6)

The code is provided here, and it is helpful for friends who are difficult to cross-origin Ajax:

 

Code
<Html>
<Head>
<Title> JQuery learning </title>
<Script src = "jquery-1.2.6.min.js" type = "text/javascript"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
Var oBtnTest =$ ("# btnTest ");
OBtnTest. click (function (){
OBtnTest. disabled = true;
Var oResult = $ ("# result ");
OResult.html ("loading" ).css ("color", "red ");
JQuery. getScript ("http://app.cntvs.com/test/js.txt ",
Function (){
OResult.html ("name:" + jimmy. name + "<br/> email:" + jimmy.email#.css ("color", "black ");
OBtnTest. disabled = false;
});
});
});
</Script>
</Head>
<Body>
<Button id = "btnTest"> BtnTest </button>
<Div id = "result"> </div>
</Body>
</Html>

 

 

The contents of the remote server js.txt are as follows:
Var jimmy = {name: "jimmy. yang", email: jimmy.yang@163.com}

Is it simpler than ExtJs's ScriptTagProxy? I personally feel that Jquery is simple and clear, short and lean, ExtJs is powerful, and rich in components!

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.