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...
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.
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).