簡體   English   中英

jQuery 使 ajax 調用無法在 iis 上運行的腳本

[英]jQuery script that makes ajax call not working on iis

從 visual studio 運行時,此腳本工作正常,但不適用於 iis。它不返回數據並失敗

error: function (xhr) {alert('error');}

可能是 url 格式嗎? 我需要添加@url嗎

<script>
function load() {
    $.ajax({
        url: '/Register/SearchResults',
        datatype: "json",
        type: 'GET',
        contentType: 'application/json',
        data: { npi: $("#NPI").val(), first: $("#First").val(), last: $("#Last").val() },
        async: true,
        processData: true,
        cache: false,
        success: function (data) {
            $("#SearchResults").empty();
            $("#SearchResults").append('<table class="table" id="records_table"><tr><th></th><th>DEA#</th><th>Life#</th><th>NPI #</th>' +
               '<th>NYS License</th><th>License Type</th><th>First Name</th>' +
               '<th>Last Name</th></tr></table>');

            for (var i = 0; i < data.length; i++) {
                $("#records_table").append('<tr id="' + data[i].NPI + '" ><td><input id="chk_' + data[i].NPI + '"  value="' + data[i].NPI + '" name="rbnSR" type="radio"></td><td>' +
                   data[i].DEA + '</td><td>' +
                   data[i].Life_Hosp + '</td><td>' +
                   data[i].NPI + '</td><td>' +
                   data[i].LIC + '</td><td>' +
                   data[i].License_Type + '</td><td>' +
                   data[i].FirstName + '</td><td>' +
                   data[i].LastName + '</td></tr>'
                   )
            }
            $("#btnSubmitBNForm").show();
        },
        error: function (xhr) {
            alert('error');
        }
    });
}

$("#btnSubmit").click(function (evt) {
    $("#searchFormError").hide();
    if ($("#NPI").val().trim() != "") {
        load();
    }
    else if ($("#First").val().trim() != "" || $("#Last").val().trim() != "") {
        load();
    }
    else {
        $("#searchFormError").show();
    }
});

$("#btnSubmitBNForm").click(function () {
    if ($('input[name="rbnSR"]:checked').length != 0) {
        $.ajax({
            url: '/Register/BNEForm?id=' + $('input[name="rbnSR"]:checked').val(),
            datatype: "json",
            type: 'POST',
            contentType: 'application/json',
            data: {},
            async: true,
            processData: true,
            cache: false,
            success: function (data) {
                if (data != "false") {
                    location.href = '@Url.Action("IdProofing", "Register")/' + data;
                }
            },
            error: function (xhr) {
                alert('error');
            }
        });
    }
    else {
        alert("Plase select a value from table");
    }
});

$("body").on("click", "#records_table tr", function () {
    $("input[type=radio]").prop('checked', false);
    $("#records_table tr").removeClass("success");
    $(this).addClass("success");
    $("#chk_" + $(this).attr("id")).prop('checked', true);
});


</script>

在所有網址中使用 @Url.Action(..) 。 它應該在視覺工作室和發布到 iis 時都有效

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM