PDA

View Full Version : jquery json problem - win vs unix?


snoodle
03-05-2009, 04:43 AM
I finally broke down and started using json for ajaxing data between client and server code (javascript/php in my case).

I am using JQuery. From the client side, the code uses the JQuery JSON plugin and goes something like...

function ClientRequest() {
var data = new Object();
data.command = "get_records";
data.data_records = "";
var dataString = $.toJSON(data);
$.post('mediabox.php', {data: dataString}, done_func);
}

function done_func(res){
var obj = $.evalJSON(res);
...
}

On the server side, the PHP code looks something like...

<?php

$res = json_decode($_REQUEST['data']);
...
...
echo json_encode($res);

?>

This all works fine on my Windows machine, however, when I upload the code to my provider (UNIX server), the code no longer works properly. The value of $res that is fed to done_func(res) is null.

I believe the problem has something to do with quotes. The $.toJSON() function returns something like "{"one":"1","two":"2"}". I've tried changing the double quotes to singles, but that didn't work. When I hard code some values without using the double quotes, it works fine on both servers, but when the double quotes are added, the value of "res" turns to null (on the Unix server only).

What am I missing?

snoodle
03-05-2009, 07:31 AM
Oooooooh. That was a fun few hours... The "magic_quotes" flags on my provider's server were set to On while my local "php.ini" had them set to false.

Kor
03-05-2009, 11:35 AM
You should have known that javascript and JSON have nothing to do with the Operating System. The only thing that matters for the client-side languages is the browser. Nor javascript/php would will be influenced by the Operating System: it is just a dialogue between the user (via his browser) and the server. Now, if the server is instructed to recognize php, it will do it, nomatter it is an Unix or a Windows system based server.