Rahul Singh
Rahul Singh

Reputation: 1632

Problem while sending data through jquery

I am sending data through jquery. my equivalent code is...

$('#pcpmnum').blur(function(){
//alert("HIiiiiii");
var pcpmnum = $("#pcpmnum").val();
if(pcpmnum === "" | pcpmnum === null)
    { 
        alert("Please Enter Mobile Number");
    }
else
    {
        alert(pcpmnum);
        $.post("searchpcp.php", {cntctnumber: "+pcpmnum+"}, function(){
            alert("Success");
                    }
    }

});

on my php file I have simply used.

echo "HIIII";

Is this $.post function is equivalent to Ajax function?

Upvotes: 0

Views: 77

Answers (1)

Rafay
Rafay

Reputation: 31033

simply do

  {cntctnumber: pcpmnum, second:"second variable" }

and in the php file you can get the value as

$contact = $_POST["cntctnumber"]; // you will get the value of pcpmnum here
$sec = $_POST["second"]; // you will get "second variable" here

in the success call back the argument data in your case contains the server response e.g. in you php file you are echoing

...
echo"howdy";

on the client side data will be holding this response

 $.post("searchpcp.php", {cntctnumber: pcpmnum, second:"second variable" }, function(data){
            alert(data);//howdy
           });

here are some useful links

jQuery, Ajax, Json and Php

Returning JSON from PHP to JavaScript?

Upvotes: 2

Related Questions