2

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?

3
  • Isn't it echo "PHP a= " . $_GET["a"] . " b= " . $_GET["b"];? Commented Mar 14, 2015 at 10:13
  • OP, add this to mytest.php: echo "<pre>"; ob_start(); var_dump('$_GET',$_GET,'$_POST',$_POST,'$_COOKIE',$_COOKIE,'$_FILES',$_FILES); echo htmlentities(ob_get_clean(),ENT_SUBSTITUTE).'</pre>'; Commented Mar 14, 2015 at 11:48
  • Yes, thank you. I thought .load is using GET but it is actually using POST. With $_POST it works. From the JQuery .load documentation: "The POST method is used if data is provided as an object; otherwise, GET is assumed." I should have seen that... Commented Mar 14, 2015 at 13:33

2 Answers 2

1

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

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

1 Comment

you forgot the second _GET
0

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"];

Comments

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.