no Callback in JSONP in an iframe with data

荒凉一梦 提交于 2019-12-11 20:22:58

问题


I am using chrome.

I have an iframe in which i require to hit a url that supports jsonp.

so i used this code :

$.ajax({
    dataType: 'jsonp', 
    url: my_url.endpoint + '/login/v1/token' ,
    data: form_to_object("#signin_form"),
    context: window,
    // All Ajax calls to ABC are json

    // Response statuses other than 200 are caught in a timeout
    timeout: 10000, //10s

    // Handler for successful calls to ABC: calls that return with statusCode 200
    success: function(data, textStatus, jqXHR) {
    // console.log(data);
    alert("in access_token success");
    if (data.hasOwnProperty('error_flag')) {
        // Errors associated with this action are caught here:
        //    invalid_credentials, account_lockout, etc.
        if (data.hasOwnProperty("jump")) {
            ABC_show_frame(data.jump);
        } else {
            ABC_error_handler(data);
        }

        return;
    } 

    // Auth succeeded, we can log in the user
    GetUserProfile(data);
    // ABC_success_handler(data);
},

error: function(data, textStatus, jqXHR) {
    alert("In access_token error");
   if (data.hasOwnProperty("jump")) {
        ABC_show_frame(data.jump);
    } else {
        ABC_error_handler(data);
    }
}
});

Now this code does not attach a callback=some_random_function_name in the url that it generates after attaching the parameters of data.

like https://abc/login/v1/token?username=ashish?password=abc but no callback.

When i debug it line by line, it do call the url with callback=something, and it seems to work. (seems because may be sometime it does not attach even in debugging line by line.)

But when i just run it, it does not.

I think that may be the problem is a bug in jquery where it also has to attach data that it got from form_to_object() and may be that overrides the callback parameter. But that is just a guess.

What should i do ?


回答1:


I had a form and i was writing my own custom function that would be called when submit button of the form was clicked. In that function i was not stopping the event from propagating further. This lead to this weird errors.

$("form.ims.ajax").submit(function(event) {
    event.preventDefault();
    // do your stuff 
});

This solved the problem.



来源:https://stackoverflow.com/questions/20422125/no-callback-in-jsonp-in-an-iframe-with-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!