Are you running your example in IE? I have, in the past, had a few
issues with MooTools trying to execute JSON sent back from the server
because of a misinterpretation of the content-type in IE. Unfortunately,
I don't have an example to hand -- I'll see if I can dig one up for you
if you're still having difficulties when I get to work this morning. In
the meantime, it might be worthwhile seeing how it works without the
content-type -- strictly speaking, JSON data doesn't need this header,
as far as I'm aware, and transmitting it as plain text doesn't render it
unparsable.
On a side note, it might be worthwhile checking the response in Firebug.
Newer versions should have a "JSON" tab for data sent back as JSON --
this way, you *should* be able to see what the client is seeing returned
from your webserver, and how it is trying to parse it.
- Barry
On 11/03/2010 1:14 AM, Plair wrote:
Hi everyone,
I'm new to Mootools, i try to use JSON to get data from a server.
I made a little CGI which send this when i call it :
printf("Content-Type: application/json\n\n{\"data\":[\n{\n\"x1\":
159,\n\"y1\": 1110,\n\"width\": 840,\n\"height\": 2412\n},\n{\n\"x1\":
180,\n\"y1\": 3540,\n\"width\": 828,\n\"height\": 1077}]}");
And then i use the following function :
/* Use a AJAX request to get the article
*/
loadArticle: function(){
var request =new Request.JSON(
{
url: this.serverXml,
onComplete: function(response)
{
alert(response.data);
},
onFailure: function(){ alert('Unable to get image and tile sizes from
server!'); }
} ).send();
},
But it doesn't seem to work. When i use a simple Request, i get
correctly the stream.
I thought that my JSON source was incorrect so i made a simple JSON
file which contains the following code :
{
"data":[
{
"x1": 159,
"y1": 1110,
"width": 840,
"height": 2412
},
{
"x1": 180,
"y1": 3540,
"width": 828,
"height": 1077
}
]
}
I used the same function, but result is the same ... nothing. I check
with online validators and both file and json strings seems to be
ok ... Where is my mistake ?
Thanks in advance !
--
Not sent from my Apple πPhone