2

I am using this ajax file upload script, and all works well in firefox http://valums.com/ajax-upload/

But it does not work in IE8.

EDIT: Ok, i've narrowed down the problem. In my php ajax response I do this

$result['table_1']='<b>text</b>';
echo json_encode($result);

The result I see in the IE developer tools looks like this

JOURNAL : [uploader] innerHTML = {"table_1":"<B>text&lt;\/b&gt;"}</B>

The end of the inner html got messed up, and the json got messed up with the correct ending tag somehow ending up outside the json??

I am using php 5.2

1
  • 1
    The quotes don't match. See labelrow and label Commented Nov 12, 2010 at 15:28

3 Answers 3

2

You should try validating your JSON response with JSONLint. On the other hand, if you've got PHP >= 5.3.0, you can use json_last_error() to verify what's causing PHP to fail on the encoding process.

Sign up to request clarification or add additional context in comments.

Comments

1

I had a similar problem Invalid JSON: {"text":"<H2>Update Complete&lt;\/H2&gt;"}</H2> with ie and solved it by using http://www.captain.at/howto-php-urlencode-javascript-decodeURIComponent.php (that site is no longer programming I found a similar function here What is the equivalent of JavaScript's encodeURIcomponent in PHP?) on the PHP side

$response->text .= encodeURIComponent("<H2 class='action_result'>Update Complete.</H2>");
return json_encode($response);      

and in the js I used

function showResponse(responseText, statusText, xhr, $form)  {
var response = jQuery.parseJSON (responseText);
$('#ajax_form_response')[0].innerHTML = decodeURIComponent(response.text);
}

Comments

0

Ok, I found a olution that works. This library works through an iframe, so to return text like

$result='<b id="1">text</b>';

I have to manually encode and decode the " myself because they get messed up in the iframe. So the final php looks like this

$result['table_1']=htmlentities(str_replace('"','|',getRowHTML()));
echo json_encode($result);

And then to manually decode in the javascript looks like this

   function(id, fileName, responseJSON)
    {
      $('#table_1 tbody').html
      (
         //this line decodes responseJSON.table_1
         $("<div/>").html(responseJSON.table_1.replace(/\|/g,'"')).text()
      );
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.