Ajax和ASP.NET完整字符串未正确发送

时间:2016-01-26 20:52:08

标签: c# jquery asp.net ajax

我有一个像这样的ajax调用:

    $.ajax({
        type: "GET",
        url: "/api/connection/NotifiyNextDepartment?questionId=" 
             + highestValue + "&department=" + jobTitle + "&customerId=" + customerID + "&jobNumber=" 
             + $("#communtiyDropdown").val() + $("#lotDropdown").val(),
        dataType: "json",
        cache: false,
        success: function (data) {}
    });

    alert('Success, you\'re data has been saved!');

    holder = [];
},
failure: function (errMsg) {
    alert('Failed, somthing went wrong, please try again!');
}

jobTitle等同于“人力资源和客户体验经理”

当我将它发送到.NET时,我只能得到它:

public bool NotifiyNextDepartment(int questionid, string department, int customerId, string jobNumber)
{
}

此处department等于“人力资源”

为什么.NET会删除&之后的所有内容。以及如何解决此问题?

1 个答案:

答案 0 :(得分:1)

我认为您应该在参数上调用encodeURIComponent

url: "/api/connection/NotifiyNextDepartment?questionId=" 
         + encodeURIComponent(highestValue) + "&department=" + encodeURIComponent(jobTitle) + "&customerId=" + encodeURIComponent(customerID) + "&jobNumber=" 
         + encodeURIComponent($("#communtiyDropdown").val() + $("#lotDropdown").val()),