Jquery+thinkphp method of implementing cross-domain Fetch data

Source: Internet
Author: User

jquery $.post send data to the server background, in the background of the PHP code to perform a remote crawl, to the database Ajax return data to the foreground, the front desk with JS to accept data and display.

Fetching Data remotely
$ ("#update_ac"). Click (function () {
$username = $ ("#username"). Text ();
$ ("#AC, #rank, #Submit, #solved, #solved2, #solved3"). Ajaxstart (function () {
$ (this). HTML ("<span class= ' loading2 ' > </span>");
});
$.post ("update_ac/username/" + $username, {},function ($data) {
JSON = eval ("(" + $data + ")");
$ ("#Submit"). HTML (json.data.Submit);
$ ("#AC"). HTML (Json.data.AC);
$ ("#solved, #solved2, #solved3"). HTML (json.data.solved);
$ ("#rank"). HTML (Json.data.rank);
}
), "JSON";
});

The jquery code above is still on the four floor of the more clear, tangled my is that the JSON data received

JSON = eval ("(" + $data + ")");
The eval () function computes a string and executes the JavaScript code in it.

In fact, this is still the foreground, cross-domain crawl is the extension of PHP Simple_html_dom completed (not clear can go to the Internet search, based on the development of PHP5)

Fetch the remote page to the local.

Import ("@.org.simple_html_dom");
thinkphp import extension, you have to rename the code downloaded from the Internet to simple_html_dom.class.php in the appname\lib\org directory
$html = file_get_html (' http://openoj.awaysoft.com/JudgeOnline/userinfo.php?user= '. $username); Remotely grabbed the
$ret = $html->find (' center ', 0)->plaintext; Return the data.

As shown below:

<strong><span style= "FONT-SIZE:18PX;" >/* number = Year two digits + month +id four digits */

$id = $this->student_model->save (0, $data);
$SN = Date (' Y ', Time ());
$SN = substr ($SN,-2);
$sn. = Date (' m ', Time ());
$sn. =sprintf ("%04d", $id);</span></strong>

Jquery+thinkphp method of implementing cross-domain Fetch 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.