我有一个在我的开发服务器上的VS 2013上运行良好的Web应用程序,但是一旦我在IIS 7.5 2008 R2服务器上发布它,位于我的自定义脚本文件上的Ajax脚本就不再工作了,尽管其他JQuery脚本不调用Ajax的工作正常.为了让ajax在服务器上工作,还有什么需要做的吗?我已经阅读了一些帖子,但还没有找到答案.我在IIS和Ajax方面的经验有限.
//更新:
我已经发现Ajax脚本有效,问题最有可能发生在以下行:
"url:'/ Home/GetRates',//请求的网址"
使用debuger我发现远程服务器中没有调用GetRates()函数,尽管它位于本地(Under VS 2013)开发服务器中.我看到的唯一区别是路径,但不知道如何解决它.以下是Ajax脚本:
// Retrieve rates and update partial view
$(function () {
$('#reservSearch').submit(function () {
if ($(this).valid()) {
$("#theModal").modal("show"); // Display the in progress.....
$.ajax({
url: '/Home/GetRates', // URL for the request
data: $("#reservSearch").serialize(), // the data to send (will be converted to a query string)
type: "POST", // whether this is a POST or GET request
dataType: 'html', // the type of data we expect back
success: function (data) …Run Code Online (Sandbox Code Playgroud) 我的代码是:
var test = "it isn't working";
var response = $.ajax({
type: 'GET',
url: 'jquerydemo.php', //This is in the same site as the page calling this request, so it's not a same-domain error.
success: function(){
test = "it's working";
},
error: function(){
alert("Error detected");
}
}).responseText;
alert(test);
Run Code Online (Sandbox Code Playgroud)
我测试了状态代码,它出现了200并且错误函数永远不会消失,但成功函数也没有.就像我在评论中所说的那样,它不是同源政策错误.它只是停留说"它不起作用".这里发生了什么?