Use ajax to post the following values Program Debugged: = F. user_age.value;VaR usersex = F. user_sex.value;// The URL of the receiving form var url = "/ajax_output.php"; // The value of post, and connect each variable through & to VaR poststr = "User_name =" + username + "& user_age =" + userage + "& user_sex =" + usersex;// Instantiate Ajax // var Ajax = initajax (); VaR Ajax = false; // Start initializing the XMLHTTPRequest object If (window. XMLHttpRequest) {// Mozilla Browser Ajax = new XMLHttpRequest (); If (Ajax. overridemimetype) {// sets the mime category Ajax. overridemimetype ("text/XML "); } } Else if (window. activexobject) {// IE browser Try { Ajax = new activexobject ("msxml2.xmlhttp "); } Catch (e ){ Try { Ajax = new activexobject ("Microsoft. XMLHTTP "); } Catch (e ){} } } If (! Ajax) {// exception. An error occurred while creating the object instance. Window. Alert ("the XMLHTTPRequest object instance cannot be created ."); Return false; } // Open the connection Ajax in post mode. open ("Post", URL, true); // defines the HTTP header information of the transmitted file Ajax. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded"); // send post data Ajax. send (poststr); // get the Ajax execution status. onreadystatechange = function (){ // If the execution status is successful, the returned information is written to the specified layer. If (Ajax. readystate = 4 & Ajax. Status = 200 ){ MSG. innerhtml = Ajax. responsetext; } } } </SCRIPT> <body> <Div id = "MSG"> </div> <form name = "user_info" method = "Post" Action = ""> Name: <input type = "text" name = "user_name"/> <br/> Age: <input type = "text" name = "user_age"/> <br/> gender: <input type = "text" name = "user_sex"/> <br/> <input type = "button" value = "Submit Form" onclick = "saveuserinfo () "> </form> </body> the preceding page is stored as Ajax. PHP then creates another PHP file, ajax_output.php <? Echo $ _ post ['user _ name']; Echo $ _ post ['user _ age']; Echo $ _ post ['user _ sex'];?>
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.