Hi DW.

I'm trying to post data without refreshing the page using the ajax, and its works fine the problem is that on the response I also get the array data that I posted to my php file then at the end of response is the returned data which is echoed from my php file. I post 3 data which are from my form but the problem is that on my response this data is also shown when I do alert(response); please check attached image and you will see that on the alert response firstly the array of what I posted to my php file is returned then my response is returned at the end of the response.

My question is how can I only show the returned response not what I posted to my php file?

$(document).ready(function(){
$("#btn").click(function(){
var custdata = $("#custom_str1").val();
var vname = $("#name").val();
var vemail = $("#email").val();
if(vname=='' && vemail=='')
{
alert("Please fill out the form");
}
else if(vname=='' && vemail!==''){alert('Name field is required')}
else if(vemail=='' && vname!==''){alert('Email field is required')}
else{
$.post("pass.php", //Required URL of the page on server
{ // Data Sending With Request To Server
custom_str1:custdata,
name:vname,
email:vemail
},
function(response){ // Required Callback Function

if(response == "Mr.M"){
    var mdqq = document.getElementById("suc");
    if(mdqq.style.display === "none"){
        mdqq.style.display = "block";
    }
}else{

      var ssgd = document.getElementById("sucaa");
      if(ssgd.style.display === "none"){
          ssgd.style.display = "block";
      }
    }
alert(response);//"response" receives - whatever written in echo of above PHP script.

$("#form")[0].reset();
});
}
});
});

On my php file I simply echo the name that was posted echo $_POST['name']; then on my callback I'm trying to check if this name is Mr.M and if its Mr.M the I show the success alert else danger alert. Please look at the image and see where Mr.M is so what I want is to simply get Mr.M not the array of the data I submitted to the php file.

Figured out the problem. On my php file there is a part where I try to send what ever was posted to this file and send it by email, for some reasons that I don't know the POST data is not included in the email and I tried to use var_dump which was what turns out to print back the posted data to my ajax response.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.