How can I use ajax to submit the data in a div to php in the background for execution? How can I use ajax to submit the data in a p file to php in the background for execution?
Reply content:
How can I use ajax to submit the data in a p file to php in the background for execution?
Write a jQuery example. Suppose you want to obtain
123
And save it.
Var t = $ ('# content '). text (); $. post ('up. php', {text: t}, function (d) {/* after the message is sent successfully, execute */});
up.php
As long as the page is used in the same way as the normal form$_POST['text']
You can get the parameters passed in.
In Native js, You Need To splice the string like this
// CreateRequest () is a self-written compatible function request = new createRequest (); var data = 'content = '+ p. innerHTML + '& id =' + num; request. open ("POST", url, true); request. setRequestHeader ("Content-Type", "text/plain"); request. send (data); request. onreadystatechange = callback; // This function is specially taken out of the previously written program. It should be the QAQ copied from the Redbook that forgot function createRequest () {try {request = new XMLHttpRequest ();} catch (tryMS) {try {request = new ActiveXObject ("Msxml2.XMLHTTP");} catch (otherMS) {try {request = new ActiveXObject ("Microsoft. XMLHTTP ") ;}catch (failed) {request = null ;}} return request ;}
The first floor does not have to contain text.
Var t = $ ('# content '). text (); // or var Tsung ('{content'{.html (); $. post ('up. php', {text: t}, function (d) {/* after the message is sent successfully, execute */});