0

I have a web app that in which I have a jQuery call to a PHP script that returns JSON.

When I run the PHP script from the jQuery call I get one result but when I run the PHP script from the web address I get a different result.

I think when I send the variables through the jQuery call:

$.post("http://myweb.php", {
            u: u,
            j: j
        })
        .done(function (data) {


            alert(data.status );
            //alert("Data Loaded: " + data);
        });

Something is getting appended to them. Because like I said earlier when I simply put in my browser:

myweb.php?u=m&j=e

I get the correct results from the MySQL call that is made.

I am trying to see what I run for my MySQL call when the jQuery is run but I am having trouble debugging the PHP script that is called. I put this line of code in the PHP:

console.log($query);

But I am not seeing its output or maybe I am looking in the wrong place in chrome for it...

2
  • You could install a php debugger, e.g. netbeans.org/kb/docs/php/debugging.html Commented Jul 3, 2015 at 17:43
  • When you make the call from a browser tab you are using GET, when you make the call with jQuery you are using POST. I would start debugging based on that information. My assumption is that in the PHP file you are using $_GET['u'] when you should be using $_POST['u']. Commented Jul 3, 2015 at 17:45

2 Answers 2

1

Notice that in your jQuery call you are using "post" and when checking it from browser, it is done by "get", so that might be one of the issues.

How are you getting the variables in PHP? ($_GET | $_POST | $_REQUEST)?
Try by changing your jQuery ajax call to do it through GET instead POST.

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

1 Comment

one can "resend XHR" with Chrome/FireFox - therefore it doesn't really matter if $_GET or $_POST...
0

In your PHP file:

<?php
// your stuff...
echo $sqlQuery;

?>

In your JavaScript file:

.done(function (data) {
    console.log(data);
});

And then check your developer console for the answer (F12 in most browsers).

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.