小编Jon*_*ins的帖子

我可以在不在URL中添加'?callback ='参数的情况下创建jQuery JSONP请求吗?

服务器不会接受请求URL中的任何参数,因此我需要删除URL中的所有额外参数,当然我无法控制服务器.

jQuery的:

$.ajax({
    type: 'GET',
    url: 'http://cross-domain.com/the_jsonp_file,
    jsonpCallback: 'jsonCallback',
    contentType: 'application/json',
    cache: 'true',
    dataType: 'jsonp',
    success: function(json) {
        console.log(json);
    },
});
Run Code Online (Sandbox Code Playgroud)

JSONP文件:

jsonCallback({"test": "hello"});
Run Code Online (Sandbox Code Playgroud)

当我发送Ajax请求时,URL如下所示:

http://cross-domain.com/the_jsonp_file?callback=jsonCallback
Run Code Online (Sandbox Code Playgroud)

但我需要这个(没有参数):

http://cross-domain.com/the_jsonp_file
Run Code Online (Sandbox Code Playgroud)

编辑:

这是我的整个情况:

function MyClass(imgs) {
    // imgs is array of URLs
    this.imgs = imgs;

    this.submit = function() {
        // button click event triggers this method
        this._show();
    };

    this._show = function() {
        var _this = this;

        for (var i = 0; i < _this.imgs.length; i++) {
            (function($, j) {
                $.ajax({
                    type: 'GET',
                    url: …
Run Code Online (Sandbox Code Playgroud)

javascript ajax jquery jsonp cross-domain

8
推荐指数
1
解决办法
3万
查看次数

标签 统计

ajax ×1

cross-domain ×1

javascript ×1

jquery ×1

jsonp ×1