jquery uses $.getjson () cross-domain Large data volume request method

Source: Internet
Author: User

The $.get and $.post methods of JQ are not accessible across domains. $.getjson let us see the dawn of Hope,

However, one thing that is not enough is that this is a get method, the parameters passed are limited, the maximum is not more than 2,083 characters.

But there is a solution to the problem, and the analysis concludes that the solution is as follows:

A.com uses $.getjson to send a request to B.Com, and at the same time, A.com put the required content into a temporary file (or Membercache),

B.Com receives the request, in turn, requests the required data to the a.com, takes the necessary action, and returns the successful information to a.com. This achieves the goal of cross-domain Big data volume requests.

Of course, the communication process, it is better to add a protocol, safety reasons.

JS Code:

View Plain$.getjson (target_url+ "? jsoncallback=?",         {           ' userid ': <?php echo $userid;? >       ,         function (result) {           if (result! = ' SC ') {               alert (result);           } else{               top.document.getElementById ("menu"). src = $ (' #url_ ' +bid). Val () + "admin/left_menu.php";               Top.document.getElementById ("main"). src = $ (' #url_ ' +bid). Val () + "admin/index_body.php";           }   });   

PHP Service-side code:

Header (' Content-encoding:plain ');   = SS ($_request[' userid ');   // Logic Code   $msg =  sc;   = Json_encode (Array ($msg));  echo $_request[' Jsoncallback ']. ' ('. $json _str. ') ';  Exit;  

Header (' Content-encoding:plain ');

This sentence is very important, if there is no such sentence, under IE6 will not be able to return information, resulting in the callback function can not be executed.

In addition, the statement found on the internet has not been verified

<a href= "javascript:void (0);" ></a> as a Submit button will also cause IE6 to $.getjson error.

The submit button cannot be placed in the <form> tab, otherwise the form interrupts the HTTP request sent by $.getjson.

Transferred from: http://www.cnblogs.com/fullhouse/archive/2012/01/05/2313814.html

jquery uses $.getjson () cross-domain Large data volume request method

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.