在带有数据的iframe中无法回调JSONP [英] no Callback in JSONP in an iframe with data

查看:122
本文介绍了在带有数据的iframe中无法回调JSONP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用chrome。

我有一个iframe,我需要点击一个支持jsonp的url。



所以我用这个代码:

  $。ajax({
dataType:'jsonp',
url:my_url.endpoint +'/ login / v1 / token',
data:form_to_object(#signin_form),
context:window,
//所有Ajax调用ABC是json

// 200以外的响应状态会在超时中被捕获
timeout:10000,// 10s

//成功调用ABC的处理程序:调用statusCode返回200
成功:function(data,textStatus,jqXHR){
// console.log(data);
alert(in access_token success);
if(data.hasOwnProperty('error_flag')){
//与此操作相关的错误在此处被捕获:
// invalid_credentials,account_lockout等
if(data.hasOwnProperty (跳)){
ABC_show_frame(data.jump);
} else {
ABC_error_handler(data);
}

return;
}

// Auth成功,我们可以登录用户
GetUserProfile(data);
// ABC_success_handler(data);
},

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

现在这段代码不会附加 callback = some_random_function_name data 的参数之后它会生成的url中。

https:// abc / login / v1 / token?username = ashish?password = abc 但没有 callback



当我逐行调试它时,它会调用回调=东西,它似乎工作。 (看起来是因为可能有时它并不附加,即使在逐行调试中也是如此)。

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



我认为这可能是jquery中的一个bug,它也必须附加从 data > form_to_object(),可能会覆盖回调参数。但这只是一个猜测。



我该怎么办? p>我有一个表单,我正在编写自己的自定义函数,当点击表单的提交按钮时会调用它。在这个功能中,我并没有阻止事件进一步传播。这导致这个奇怪的错误。

  $(form.ims.ajax)。submit(function(event){
event.preventDefault();
//做你的东西
});

这解决了这个问题。


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 ?

解决方案

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.

这篇关于在带有数据的iframe中无法回调JSONP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆