Skip to content

JSONP and parsing responseText upon 409 Conflict #4771

Closed

Description

@fras2560

Bug Reports:
Unable to parse responseText of JSONP in a error handler.

  • What do you expect to happen? Able to parse the JSON
  • What actually happens? Get a parsing error
  • Which browsers are affected - Chrome/Firefox?

Currently using Backbone and JQuery. Recently have upgraded from 3.3.1 to 3.5.1. Essentially, backbone is using a jsonp request to delete a model but expecting a 409 due to the model being unable to be deleted. It works as expected and end up in the error handler but the responseJson is not present. I have walked through the stack trace difference between 3.3.1 & 3.5.1. The reason seems to be a parsing error:

error: Error: jQuery35109401972421271656_1597775421415 was not called at Function.error (3.5.1/jquery.js:334:9) at s.converters.script json (3.5.1/jquery.js:10232:12) at ajaxConvert (jquery/3.5.1/jquery.js:9260:19) at done (3.5.1/jquery.js:9736:15) at XMLHttpRequest.<anonymous> (3.5.1/jquery.js:10047:9) message: "jQuery35109401972421271656_1597775421415 was not called" stack: "Error: jQuery35109401972421271656_1597775421415 was not called state: "parsererror"

From walking through the stacktrace it seems related to - 50871a5

Activity

  1. mgol commented on Aug 18, 2020

    @mgol
    Member

    Thanks for the report.

    We considered #4379 to be a bug fix but JSONP is a bit special, indeed - under the hood it's a script but it simulates JSON responses in an environment without a CORS setup and sending JSON payloads on error responses is quite typical there. Maybe we need to revisit the JSONP case.

    It'd help if you could provide a minimal test case or - even better - a test case for the jQuery test suite, something like

    jquery/test/unit/ajax.js

    Lines 809 to 922 in 82b87f6

    ajaxTest( "jQuery.ajax() - do not execute scripts from unsuccessful responses (gh-4250)", 11, function( assert ) {
    var globalEval = jQuery.globalEval;
    var failConverters = {
    "text script": function() {
    assert.ok( false, "No converter for unsuccessful response" );
    }
    };
    function request( title, options ) {
    var testMsg = title + ": expected file missing status";
    return jQuery.extend( {
    beforeSend: function() {
    jQuery.globalEval = function() {
    assert.ok( false, "Should not eval" );
    };
    },
    complete: function() {
    jQuery.globalEval = globalEval;
    },
    // error is the significant assertion
    error: function( xhr ) {
    assert.strictEqual( xhr.status, 404, testMsg );
    },
    success: function() {
    assert.ok( false, "Unanticipated success" );
    }
    }, options );
    }
    return [
    request(
    "HTML reply",
    {
    url: url( "404.txt" )
    }
    ),
    request(
    "HTML reply with dataType",
    {
    dataType: "script",
    url: url( "404.txt" )
    }
    ),
    request(
    "script reply",
    {
    url: url( "mock.php?action=errorWithScript&withScriptContentType" )
    }
    ),
    request(
    "non-script reply",
    {
    url: url( "mock.php?action=errorWithScript" )
    }
    ),
    request(
    "script reply with dataType",
    {
    dataType: "script",
    url: url( "mock.php?action=errorWithScript&withScriptContentType" )
    }
    ),
    request(
    "non-script reply with dataType",
    {
    dataType: "script",
    url: url( "mock.php?action=errorWithScript" )
    }
    ),
    request(
    "script reply with converter",
    {
    converters: failConverters,
    url: url( "mock.php?action=errorWithScript&withScriptContentType" )
    }
    ),
    request(
    "non-script reply with converter",
    {
    converters: failConverters,
    url: url( "mock.php?action=errorWithScript" )
    }
    ),
    request(
    "script reply with converter and dataType",
    {
    converters: failConverters,
    dataType: "script",
    url: url( "mock.php?action=errorWithScript&withScriptContentType" )
    }
    ),
    request(
    "non-script reply with converter and dataType",
    {
    converters: failConverters,
    dataType: "script",
    url: url( "mock.php?action=errorWithScript" )
    }
    ),
    request(
    "JSONP reply with dataType",
    {
    dataType: "jsonp",
    url: url( "mock.php?action=errorWithScript" ),
    beforeSend: function() {
    jQuery.globalEval = function( response ) {
    assert.ok( /"status": 404, "msg": "Not Found"/.test( response ), "Error object returned" );
    };
    }
    }
    )
    ];
    } );
    but for JSONP & a different expected result. Would you want to try that?

  2. added
    Discuss in MeetingReserved for Issues and PRs that anyone would like to discuss in the weekly meeting.
    on Aug 18, 2020
  3. fras2560 commented on Aug 18, 2020

    @fras2560
    ContributorAuthor

    @mgol Thanks for the quick response. I will give it a try to make a test case or at the very least a minimal test case. I hope I correctly described the situation but will confirm for sure (bit complicated with Backbone, Server, and JQuery).

  4. mgol commented on Aug 18, 2020

    @mgol
    Member
  5. fras2560 commented on Aug 20, 2020

    @fras2560
    ContributorAuthor

    @mgol I think I have fix for the issue and wrote up a simple test. However, I am not too familar with PHP so I might need some help with this. I am not even sure how to run it locally. Also, need some help with response body

    #4773

  6. added this to the 3.6.0 milestone on Aug 22, 2020
  7. removed
    Discuss in MeetingReserved for Issues and PRs that anyone would like to discuss in the weekly meeting.
    on Aug 24, 2020
  8. added 4 commits that reference this issue on Aug 25, 2020
    a1e619b
    3bae54a
    fc13a09
    68b4ec5
  9. deleted a comment from on Feb 2, 2025
  10. locked as resolved and limited conversation to collaborators on Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions