开发者

jQuery JSON issue in IE7&8, not in FF or Chrome (already checked for extra commas!)

I've got an annoying issue with an ajax upload script which is throwing an error in IE7 and 8. I've looked over my code and can't see what the problem could be. The error is as follows:

Message: 'result.filename' is null or not an object

The JSON response is: responseText = {"result":{"success":true,"filename":"autechrea8d7909a2e964c36e04d9f53eea54f6c"},"id":98}

I can access responseText.result.filename fine in other browsers - any idea what could be causing the IE issue?

Thanks in advance!

EDIT: this is the context in which i'm accessing the JSON response:

var uploader = new qq.FileUploader({
                element: document.getElementById('file-uploader'),
                action: '<?php echo url::base(TRUE) ?>page_images/create/' + page_id,
                debug: true,
                onComplete: function(id, fileName, responseJSON){
                    path = '/media/images/main_images/new_uploads" ?>';
                    path = path + '/' + String(responseJSON.result.filename) + '.jpg';
                    $('.page_images').prepend(
                    '<li style = "float:left; display: inline; margin-right: 5px; width: 110px; height: 140px;">' +
                    '<img src = "' + path + '" width = "100" height = "100" />' +
                    '<br />' +
                    '<a href= "/page_images/delete/' + responseJSON.id + '">' +
                    '<img src= "/media/images/icons/cross.png" alt="Delete" title="Delete" />' +
                    '</a>' +
                    '</li>');
                    delete开发者_如何转开发Handler();
                }
        }); 


I've had the same problem, in your Action where you return your Json result change your content type to "text/html" like this:

        return Json(new { success = false }, "text/html");

For whatever reason IE doesn't like it any other way.


Is there a typo in this line or do you really want a double quote and "?>" in path.

path = '/media/images/main_images/new_uploads" ?>';

Also, you really should declare all your variables. I think you want something like this:

var path = '/media/images/main_images/new_uploads';

Maybe the stray double quote is confusing IE when the HTML is injected. It isn't like the IE error messages are all that helpful.

I'd also suggest that you replace String(responseJSON.result.filename) with just responseJSON.result.filename to cut down on the noise.

Other than that, I'd suggest you look carefully at the blob of HTML that you're prepending. You could also inline the JSON data and see what happens.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜