Ajax POST FormData在https(安全链接)中不起作用

时间:2018-07-30 11:22:15

标签: javascript jquery asp.net https

我们正在尝试将图片上传到我们的服务器。它在 http 网站上工作正常,但在 https 网站上工作不正常。

它引发以下情况:enter image description here 无法加载资源:服务器响应状态为500(内部服务器错误) 这是用于ajax的代码

Java脚本

function fnTest(){
var iTaskID = $("#hdnCurTaskID").val();
var files = $("#TaskImg")[0].files;
if (files.length > 0) {
    if (files.length > 3) {
        alert("Maximum 3 files Allowed");
        return;
    }
    if (typeof FormData == "undefined") {
        var postdata = [];
        for (var i = 0; i < files.length; i++) {
            postdata.push("UploadedFile", files[i]);
        }
        postdata.push("TaskID", iTaskID);
    }
    else {
        var postdata = new FormData();
        for (var i = 0; i < files.length; i++) {
            postdata.append("UploadedFile", files[i]);
        }
        postdata.append("TaskID", iTaskID);
    }
    $.ajax({
        type: "POST",
        url: "TaskStatus.asmx/UploadExecTaskPic",
        contentType: false,
        processData: false,
        async: false,
        responseType: "json",
        data: postdata,
        success: function (result) {
            var MaxFile = GetSessionValuecurrent(iTaskID);
            if (MaxFile == "MaxFile") {
                alert("Maximum 3 Files only Allowed to Upload");
            }
            else {

                $("#TaskImg").val("");
                $("#TaskImg").replaceWith($("#TaskImg").clone());
                DoCloseFileSelector();
                DoShowTaskImages(iTaskID, '');
            }
        },
        error: function () {
            alert("Upload Error");
        }
    });
}
}

网络方法:

[WebMethod(EnableSession = true)]
public string UploadExecTaskPic()
{
    string sResult = string.Empty;
    return sResult;
}

1 个答案:

答案 0 :(得分:1)

我在Google搜索中遇到了此信息

FIX Request format is unrecognized for URL unexpectedly ending in

  

将以下内容添加到web.config中,因为ASP.NET 2.0和更高版本默认情况下禁用GET和POST:

steps {
  // I already had 'steps', below was added.
  script {
    response = sh(
      returnStdout: true, 
      script: "curl -X POST ..."
    );
    // The response is now in the variable 'response'

    // Then you can regex to read the status. 
    // For some reasen, the regex needs to match the entire result found.
    // (?s) was necessary for the multiline response.
    def finder = (response =~ /(?s).*HTTP/1.1 (\d{3}).*/);
    if (finder) {
      echo 'Status ' + finder.group(1);
    } else {
      echo "no match";
    }
  }
}