sbehnsen
sbehnsen

Reputation: 53

JQuery load with parameters to PHP

I am trying to use JQuery .load to get data from a PHP script file, but for some reason I can not get my parameters in the PHP script.

My load call (I don't really need the alert, but I put it in just to be sure):

    $("#m_target").load("mytest.php", { a:"def", b:"1234" }
             ,function(data){alert("Data: " + data);}               
    ); 

My PHP script file (mytest.php):

<?php
    echo "PHP a= " , $_GET["a"], " b= ", $_GET["b"];
?>

I have tried .post and .get as well, but without success.

All I get is "PHP a= b= " I have checked with wireshark, and the parameters are transmitted with the .post call, so why can I not see/access them in the php script?

Upvotes: 2

Views: 118

Answers (2)

SirFoomy
SirFoomy

Reputation: 11

If your parameters are submitted by post, you have to access them in the $_POST array.

<?php
  echo "PHP a= " , $_POST["a"], " b= ", $_GET["b"];
?>

Regards Sascha

Upvotes: 1

Ne Ma
Ne Ma

Reputation: 1709

In your example you are posting the variables. But you are referencing GET.

Change

echo "PHP a= " , $_GET["a"], " b= ", $_GET["b"];

to

echo "PHP a= " , $_POST["a"], " b= ", $_POST["b"];

Upvotes: 0

Related Questions