在带有数据的iframe中的JSONP中没有回调

no Callback in JSONP in an iframe with data

本文关键字:JSONP 中的 回调 iframe 数据      更新时间:2024-04-26

我正在使用chrome。

我有一个iframe,我需要在其中找到一个支持jsonp的url。

所以我用了这个代码:

$.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);
    }
}
});

现在,此代码在附加data的参数后生成的url中不附加callback=some_random_function_name

像CCD_ 3但没有CCD_。

当我一行一行地调试它时,它确实用callback=something调用了url,而且它似乎可以工作。(似乎是因为有时它甚至在逐行调试时都不会连接。)

但当我只是运行它时,它不会。

我认为这可能是jquery中的一个错误,它还必须附加从form_to_object()获得的data,并且可能覆盖了callback参数。但这只是猜测。

我该怎么办?

我有一个表单,我正在编写自己的自定义函数,当单击表单的提交按钮时会调用该函数。在那个函数中,我并没有阻止事件进一步传播。这导致了这种奇怪的错误。

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

这解决了问题。