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