ConorBaumgart ConorBaumgart - 1 year ago 73
PHP Question

Ajax post request is appending sent data to the returned JSON

I have an ajax call like so:

url: '/assets/functions.php',
type: 'POST',
data: {
"functionCall": "get-uploads",
"type": type
dataType: 'json',
success: function (data, textStatus) {
error: function(textStatus, errorThrown) {
console.log("uh oh");

Which gets sent to and handled with this:

switch($_POST['functionCall']) {
case "get-uploads":

$type = $_POST['type'];
$getUploads = "SELECT * FROM pp_uploads WHERE type = '$type';";

$docArray = array();

while($row = mysql_fetch_assoc($documents)) {
$docArray[] = $row;

echo json_encode($docsArray);

When I run this I get a parsing error, which from what I understand means that the returned data isn't being returned as JSON. So I changed the dataType to html, and I see that the returned data in the console is:

[functionCall] => get-uploads
[type] => resources

So it looks like the data I passed into the call is being appended to the end of my data. How do I prevent that from happening?

Answer Source

It looks like you might be doing a print_r somewhere on an Array variable?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download