简体   繁体   English

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

[英]Ajax POST FormData not working in https(Secured Link)

We are trying upload pictures to our server. 我们正在尝试将图片上传到我们的服务器。 Its working fine in http sites, but not in https sites. 它在http站点上可以正常工作,但在https站点上却不能。

It throws following: 它引发以下内容: 在此处输入图片说明 Failed to load resource: the server responded with a status of 500 (Internal Server Error) Here is the code which is used for ajax 加载资源失败:服务器响应状态为500(内部服务器错误)这是用于ajax的代码

Java Script 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");
        }
    });
}
}

Web Method: 网络方法:

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

I came across this information in a google search 我在Google搜索中发现了此信息

FIX Request format is unrecognized for URL unexpectedly ending in 无法识别FIX请求格式的URL意外结尾为

Add the following to web.config since GET and POST are disabled by default in ASP.NET 2.0 and greater: 由于在ASP.NET 2.0和更高版本中默认禁用GET和POST,因此将以下内容添加到web.config中:

<configuration>
    <system.web>
    <webServices>
        <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>
    </system.web>
</configuration>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM