Problems with Ajax in PHP

Source: Internet
Author: User
PHP Ajax PHP Ajax

 
  

function $ (ID) {return document.getElementById (ID);} function AddComment () {var url = "14-6.php", var status = document.getElementById ("divmsg"); status.value= "Submitting" "; var param = "Name=" +$ ("name"). Value+ "email=" +$ ("email"). value+ "comment=" +$ ("comment"). value;xmlhttp_ Request.onreadystatechange = function () {if (xmlhttp_request.readystate==4 && xmlhttp_request.status = = 200) {/ /corresponding full display of Information alert (xmlhttp_request.responsetext); if (Xmlhttp_request.responsetext = = "1") {Status.value = "published successfully!! "; $ (" name "). value=" "; $ (" email "). value=" "; $ (" comment "). value=" ";} Else{status.value = "Publishing failed!" Please re-publish! ";}}} Xmlhttp_request.open ("POST", url,true); Xmlhttp_request.setrequestheader ("Content-type", "application/ X-www-form-urlencoded ");//Set Header information Xmlhttp_request.send (param);}

I don't know why, this responsetext returns a large HTML code.


Reply to discussion (solution)

Above is what alert (xmlhttp_request.responsetext) returns.

Are you asking for the current page?

Isn't that the wrong message?
14-6.php the 4th Line of $_post[' email ' is not defined

var param = "Name=" +$ ("name"). Value+ "email=" +$ ("email"). value+ "comment=" +$ ("comment"). value;
Should write
var param = "Name=" +$ ("name"). Value+ "&email=" +$ ("email"). value+ "&comment=" +$ ("comment"). value;

My is from an HTML file to the PHP file.

The HTML code is below. My total is only two files, an HTML file, a PHP file

 
  Insert Title here

The problem has been solved, is the moderator said the error. When committing three different variables between &, because just touch Ajax, so the post submission is not very understanding.

  • 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.