javascript - ajaxupload 跨域上传文件 ,能返回值,但是总是进error,不进sucess ,为什么?
迷茫
迷茫 2017-05-16 13:03:07
0
3
516

$.ajaxFileUpload({

        url:"http://192.168.0.222:8080/Erp_V0.1/admin/upload/uploader.php",   //处理图片的脚本路径
        type: 'post',       //提交的方式
        data: upload_arr,//自定义参数
        secureuri :false,   //是否启用安全提交
        fileElementId :id,     //file控件ID
        dataType : "jsonp",//数据类型为jsonp
        jsonp: "jsonpCallback",//服务端用于接收callback调用的function名的参数
        success : function (data){  //提交成功后自动执行的处理函数
            alert(1111);
            alert(data);
        },
        error:function(data,status,e){
            alert(2222);
            alert(e);
            alert(JSON.stringify(data));
            alert(status);
        }
    }) 
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(3)
世界只因有你

jsonp cross-domain only supports get mode. Even if your front-end is set to post mode, it will be automatically converted to get mode.
The implementation method of jsonp is actually the same as the script request address, except that the jsonp of ajax encapsulates it. As you can imagine, jsonp does not support the POST method. Therefore, if your server-side code uses the post method, it will not be able to request.
Of course, if you force yourself to use the post method for cross-domain communication, there is nothing you can do.
Client side changes:
``
Added: crossDomain: true
Modification: dataType: "json"
``
Server side added:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST');
header('Access-Control-Max-Age: 1000');

Although it can be done, it has disadvantages and the request time is relatively long. You can weigh the pros and cons yourself.

Finally, attach a related question post on Stackoverflow:
http://stackoverflow.com/ques...

为情所困

I remember using Get for Jsonp across domains. .But if you insist on posting, there is http://www.jb51.net/article/6..., I haven’t tried it.

巴扎黑

First, let’s clear up cross-domain and jsonp related knowledge
jsonp is made with script tags
If the post is to be cross-domain, you need to add Access-Control-Allow-Origin to the backend

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!