Data is not received on PHP page using $.POST() method of jquery

+1 Altaf Husain Neva · February 23, 2015
My POST variable at PHP page is always empty still after clicking on submit button. I send data from a javascript page to php page.
Javascript code:

   if(quantityArray[j] == undefined){
       alert("Empty Form can not be submitted!");
   else {
       $.post('insert_man_order.php',{ total_price: quantityArray[j] }, function(data){

The PHP code where i should receive the value of variable total_price is:

       $price = $_POST['total_price'];
       echo "No data recieved";

One more thing here.. I have written alert by passing data into it in $.post function and it works perfect. So if data is received perfectly after passing it to another page than whats the problem in receiving it at another page?

Post a Reply


Oldest  Newest  Rating
0 Altaf Husain Neva · February 24, 2015
I have another function which is called on the keyup event and in that function the value of the array is being assigned. And this array is declared globally so i can use it in this function too. The point is when this button is clicked there are two operation performed because this button is a submit button of the form.

1) (jQuery function is called) The onclick function is called and the data is sended to PHP file and response is received.
2) (Rest Data is than submitted to PHP file) And as usual on clicking submit button the data is sended to the PHP file and that file is called again.

What I think causes the problem is: The 2 different types of operation performed o the same file thus when 1st operation is performed than $_POST['total_price'] gets the value than jQuery gets the response and that variable is destroyed (this is what i think).
and as usual the form is submitted as the button clicked was a submit button, so I try to grab the value of that $_POST['toatal_price'] and it is empty because that file according to it was called first time.

Now let me explain what i am trying to do is:

I have a form with multiple text box and in those text box user will enter quantity of different products. Now whenever user press the key i want to calculate the total amount of all the quantity entered. So I am using jQuery to calculate total amount. Now when user clicks on submit button, I want to send all this data to one PHP file which will order those products for the user. So I have two things here. One is the quantity of different products and another is total amount. The total amount is calculated using jQuery function and rest things I will directly grab from the text box when the form is submitted. So on submit button i want to send data from two different source one variable (total amount) from jQuery file and other variables (quantities) from that particular page from which the form is submitted.

So in your opinion What is the best practice I should do...????
0 Jay Deshaun · February 24, 2015
Yea, @William is right, we can't see the array for which is called in the code you posted above.
0 william appiah-dankwah · February 23, 2015
were is the array? the code calls for the code to submit but i can't see the array.i am not sure about the rest of the code though
  • 1



A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.