views:

207

answers:

3

fixed;

I'm using a simple jQuery to download text off a server, datatype json.

$.get('http://169.254.100.5/ajax.php',{action:'p',i:'{$data['id']}'},function(data)
{
     $.each(data.responses, function(i,response)
     {
       alert(response.longtext)
     }
}

When response.longtext is short (less than 1000 chars like "hello world") i have no problem and the script behaves normally.

When response.longtext is long (like a paragraph of lorem ipsum) i get a parsererror.

I did some experimenting and rewrote it using $.ajax(...) and dropped the $.each method and I still get a parser error.

error: function(XMLHttpRequest, textStatus, errorThrown) 
{
    alert("err: "  + textStatus);
}
A: 

How do you print the data in the server? Maybe you didn't escape charcters correctly. Do you use json_encode in php?

Y. Shoham
A: 

There's a good chance the response is not encoded properly. Did you try just doing eval() on the responseText?

Annie
A: 

oh. my bad, it was the \t and \n in the lorem ipsum that caused my error.

i wasnt using json_encode because im generating the json on the fly with a $stmt->fetch() loop. just slashed out the problematic characters and its fine.

Jay
Please don’t respond with an answer but edit your question.
Gumbo