Question

IE7 throws an exception: "jquery: parseerror" when running the following code. It works in all other browsers I've tested (Firefox, Opera, Chrome, Chromium).

Script:

 function check(){
            $("#form").ajaxSubmit({
                url: "/send-file",
                dataType: "json",
                success:
                    function(answer){
                        $("#result").html(answer.msg);
                        },
                error:
                    function(jqXHR, textStatus, errorThrown){
                        alert(textStatus);

                    }
                });
            return false;
    }

The server script(controller of Pylons):

  @jsonify
    def sendFile(self):
        response.content_type = "text/plain"
        response.cache_control = 'no-cache'
        response.pragma = "no-cache, must-revalidate"
        response.expires = "-1" 

        data = dict(msg = '<h1 id="sd">ffffffffff</h1> \
                <p>ddddd</p> <a href="#">link</a>' )
        return data 
Was it helpful?

Solution

the problem seems to be in the jQuery plugin for uploading files using hidden frame. If it is the plugin, than it contains an error (if i recall correctly it reads the contents of the json from the body tag). I wanted to chat on the issue with the author, but the facebook comments in his blog raised an exception. As result, I slightly fixed the plugin locally to read the whole server result.

Unfortunatelly, I currently don't have access the hacked version.

OTHER TIPS

instead if

response.content_type = "text/plain" 

try

response.content_type = "application/json"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top