0

Nothing is wrong, as soon as i change the lib to 1.3.2 my on success stuff works just fine? How comes? Not even the alert with TEST appears..

Here's the code this is happening on:

function crop() {
    $.ajax({
        type: "POST",
        dataType: 'json',
        url:"functions.php?action=crop",
        data: 
        {
            x: $('#x').val(),y: $('#y').val(),w: $('#w').val(),
            h: $('#h').val(),fname:$('#fname').val(),fixed:fixed,
            sizew:sizew,sizeh:sizeh},
            success: function(response)
            {
                alert('TEST');
                if(!fixed) // Missing { }
                { 
                    $("#showPhoto").css({overflow:"auto"}); // Missing ;
                }
                $("#showPhoto").html(
                    $(document.createElement("img")).attr(
                        "src",response.filename)).show();

                $("#showPhoto").after("There you go...").show();
                $("#image").slideUp();
           },
          error:function(response) {
                   console.log('error: ', response);
               }
        });
    }

How can i make it to work with jquery 1.4.2 library?

Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
Karem
  • 17,615
  • 72
  • 178
  • 278
  • How is this different from your previous question? http://stackoverflow.com/questions/3639317/jquery-whats-up-with-the-success – user113716 Sep 03 '10 at 22:38
  • fixed is a var fixed = 1; if the image have fixed size.. – Karem Sep 03 '10 at 22:42
  • @patrick dw, i know the main problem now, and want it to work with 1.4.2. In the other question i wanted to know what the problem is, but now i know and want to solve it – Karem Sep 03 '10 at 22:43
  • @Karem: If you know the problem, then what is it? – Guffa Sep 03 '10 at 22:47
  • @Guffa I dont know the problem i mean the issue and that the script only support the old library for some reason, that i DONT know what is – Karem Sep 03 '10 at 22:50
  • @Karem - what does your JSON response look like? My money's on it not being valid JSON :) – Nick Craver Sep 03 '10 at 23:15
  • @Nick Craver: looks like this: ({"filename":"images\/profilePhoto\/thumbs\/1283596240.jpg"}) - I dont know why the / has turned \/ , but it do still work fine with 1.3.2. – Karem Sep 04 '10 at 10:33
  • Please check updated question for links for live version of the problem – Karem Sep 04 '10 at 10:44

1 Answers1

1

The JSON coming back isn't valid, the example you posted:

({"filename":"images\/profilePhoto\/thumbs\/1283596240.jpg"}) 

And the response I got in the page:

({"filename":"1283597560.jpg"})

Both aren't valid JSON, you need to remove the () wrapper on there. You can check your JSON response for validity here: http://www.jsonlint.com/

The 1.3.2 vs 1.4.2 difference is that in 1.4.0 jQuery added strict JSON checking, if it's not valid it'll fail (so it can take better advantage of browsers' native JSON parsers).

From the 1.4 release notes:

Strict JSON parsing, using native JSON.parse: (jQuery.ajax() Documentation, Commit 1, Commit 2, Commit 3)

jQuery 1.3 and earlier used JavaScript’s eval to evaluate incoming JSON. jQuery 1.4 uses the native JSON parser if available. It also validates incoming JSON for validity, so malformed JSON (for instance {foo: "bar"}) will be rejected by jQuery in jQuery.getJSON and when specifying “json” as the dataType of an Ajax request.

Community
  • 1
  • 1
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155