0

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?

2
  • $.post is a shortcut for $.ajax so you don't have to fill in as many options. Commented Sep 6, 2011 at 10:44
  • $.post is a shorthand for $.ajax with certain presets (api.jquery.com/jQuery.post). From the code it should be calling the searchpcp.php properly, but why do you pass the pcpmnum as a string instead of passing its value (without the quotes and the +es)? Commented Sep 6, 2011 at 10:44

1 Answer 1

2

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?

Sign up to request clarification or add additional context in comments.

4 Comments

If I need to send 2 variables? Second is this is equivalent to send Ajax request? what does it mean If I use function(data)
ill edit the answer for two vars and yes $.post uses ajax call at the backend it is just the short hand for $.ajax
I want to return an array of data. and fill the respective text field from that returned data. Suppose I have input with id=firstname and my second would be 'id=middlename'. I am firing querey in my PHP file. How would I return those data.
i have posted some links hope they'll help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.