【问题标题】:Ajax POST FormData not working in https(Secured Link)Ajax POST FormData 在 https(安全链接)中不起作用
【发布时间】:2019-01-06 15:21:31
【问题描述】:

我们正在尝试将图片上传到我们的服务器。它在 http 网站上运行良好,但在 https 网站上却不行。

它抛出以下内容: 加载资源失败:服务器响应状态为 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;
}

【问题讨论】:

  • 您的服务器日志说什么是 500 错误的原因? IIS 上的默认位置 %SystemDrive%\inetpub\logs\LogFiles
  • 它说只是内部服务器错误
  • 您应该检查网络服务器日志。在那里您可以找到有关 500 错误的更多信息。 IIS 的默认位置是 %SystemDrive%\inetpub\logs\LogFiles
  • 我会检查并更新
  • 抱歉...我们没有启用 IIS 日志。检查服务器事件

标签: javascript jquery asp.net https


【解决方案1】:

我在谷歌搜索中发现了这些信息

FIX Request format is unrecognized for URL unexpectedly ending in

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-20
    • 2020-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-07
    • 2018-07-05
    • 2013-11-25
    相关资源
    最近更新 更多