【问题标题】:no Callback in JSONP in an iframe with data在带有数据的 iframe 中 JSONP 中没有回调
【发布时间】:2013-12-23 16:47:25
【问题描述】:

我正在使用 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

喜欢https://abc/login/v1/token?username=ashish?password=abc,但不喜欢callback

当我逐行调试它时,它确实使用callback=something 调用url,它似乎工作。 (似乎是因为有时它甚至在逐行调试时也没有附加。)

但是当我只是运行它时,它没有。

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

我该怎么办?

【问题讨论】:

  • 这可能是因为context : window

标签: javascript jquery google-chrome iframe jsonp


【解决方案1】:

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

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

这解决了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-25
    • 2012-06-25
    • 2011-11-28
    • 1970-01-01
    • 2017-09-28
    • 2015-07-13
    • 2013-02-16
    • 2013-05-10
    相关资源
    最近更新 更多