【问题标题】:jquery ajax contentType:false not making the boundary tag for jquery ajaxjquery ajax contentType:false 不为 jquery ajax 做边界标记
【发布时间】:2015-06-28 19:18:16
【问题描述】:

我已将我的 jQuery ajax 请求的 contentType 添加为 false。我正在发送

$.ajax({
        url : "http://groc.cloudapp.net:8000/api/view/"+tile_vert_id+"/"+tileId,
        type: "PUT",
        data :updatedemoData,
        processData: false,
        cacheControl: "no-cache",
        contentType: false,
        success : function(data,textStatus,jqXHR)
        {
            alert("Yo");
            console.log("successdata: ",data);
            $($caseToEdit).find(".tile-name").text(updatedemoData.name);
            $($caseToEdit).find(".tile-des").text(updatedemoData.description);
            $($caseToEdit).find(".v-url").text(updatedemoData.url);
            $(".ajax-loader").hide();


        },
        error : function(jqXHR,textStatus,errorThrown){
            $(".ajax-loader").hide();
            alert("error in loading!");
        }
    });

我正在为数据发送 Formdata 对象

var updatedemoData = new FormData();
        updatedemoData.name = demoName;
        updatedemoData.description = demoText;
        updatedemoData.videoordemo = tileType;
        updatedemoData.url = demoUrl;

但是当我在浏览器控制台中运行相同的代码时,我得到了边界标记。没有边界标签,数据不会保存在服务器中。

我期待这样的带有边界标签的东西

Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryiBHhkxeJP2Vc7a5Q

但内容类型其实是

Content-Type:application/x-www-form-urlencoded; charset=UTF-8

任何建议

【问题讨论】:

  • 我认为在 FormData 中附加参数应该使用.append() 方法..尝试使用那个.. 像这样updatedemoData.append("name", demoName);
  • 即使使用提到​​的updatedemoData.name = "some name"方法也可以正常工作

标签: javascript jquery ajax content-type put


【解决方案1】:

无论如何,当我在局部变量中更改上述 URL 时,我可以让它工作。

var ajaxUrl = "http://groc.cloudapp.net:8000/api/view/"+tile_vert_id+"/"+tileId,

$.ajax({
    url : ajaxUrl ,
    type: "PUT",
    data :updatedemoData,
    processData: false,
    ... 
});

当我之前尝试使用相同的代码时,该 URL 没有错误。但我不明白上述代码工作的确切原因是什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-27
    • 2013-05-31
    • 1970-01-01
    • 1970-01-01
    • 2012-02-23
    • 2011-11-26
    相关资源
    最近更新 更多