运行jQuery脚本我有一个负载执行jQuery脚本的ASP.net MVC页。 该脚本在控制器上调用一个动作并保存下拉列表。页面不负载
这个工程我的开发计算机上,但在部署到Web服务器(赢2K3机器上运行IIS 6)在页面加载,但它不运行造成空下拉列表中的脚本。
我在脚本文件夹中的jQuery的1.3.2.js文件,我已经添加了映射ASPNET_ISAPI.DLL在web服务器上。还有什么我失踪?
这是页面的一部分,可以保护在我的机器上工作的下拉列表,但不在其部署的web服务器上,因为您可以看到该脚本调用ApplicationSettings控制器以获取JSON对象,以保护下拉列表
<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
<script src="~/Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script type="text/javascript">
// Wait for the document to be ready
$(document).ready(function()
{
var selectedApp = $('#selectedApplication').val();
var selectedMac = $('#selectedMachine').val();
// Get the list of applications and populate the applications drop down list
$.getJSON("/ApplicationSettings/Applications/List", function(data)
{
var items = "<option>----------- Select Application to Configure ----------</option>";
$.each(data, function(i, application)
{
var selected = (application.Value == selectedApp) ? 'selected' : '';
items += "<option value='" + application.Value + "'" + selected + ">" + application.Text + "</option>";
});
$("#Applications").html(items);
});
// Get the list of machines where the selected application is installed and populate the machines drop down list
$("#Applications").change(function()
{
if ($("#Applications").attr("value") != "")
{
// Enable the Machines DDL if a valid application is selected
$("#Machines").removeAttr("disabled");
// Populate the machines DDL with a list of machines where the selected application is installed
$.getJSON("/ApplicationSettings/Machines/List/" + $("#Applications > option:selected").attr("value"), function(data)
{
// Set the first item in the list
var items = "<option>---------- Select Machine -----------</option>";
// Retrieve the list of machines for th selected application from the database
$.each(data, function(i, machine)
{
var selected = (machine.Value == selectedMac) ? 'selected' : '';
items += "<option value='" + machine.Value + "'" + selected + ">" + machine.Text + "</option>";
});
// Add the items retrieved to the Machines DDL
$("#Machines").html(items);
if ($("#Machines").attr("value") != "")
{
$("#btnSearch").removeAttr("disabled");
}
else
{
$("#btnSearch").attr("disabled", "disabled");
}
});
}
else
{
// If a valid application has not been selected then disable the Machines DDL
$("#Machines").attr("disabled", "disabled");
$("#btnSearch").attr("disabled", "disabled");
}
});
if (selectedApp != "")
{
$("#Machines").removeAttr("disabled");
$.getJSON("/ApplicationSettings/Machines/List/" + selectedApp, function(data)
{
var items = "<option>---------- Select Machine -----------</option>";
$.each(data, function(i, machine)
{
var selected = (machine.Value == selectedMac) ? 'selected' : '';
items += "<option value='" + machine.Value + "'" + selected + ">" + machine.Text + "</option>";
});
$("#Machines").html(items);
});
if (selectedMac != "")
{
$("#btnSearch").removeAttr("disabled");
}
else
{
$("#btnSearch").attr("disabled", "disabled");
}
}
else
{
$("#Machines").attr("disabled", "disabled");
$("#btnSearch").attr("disabled", "disabled");
}
});
function saveSelectedApplication()
{
$("#selectedApplication").val("");
$("#selectedMachine").val("");
$("#selectedApplication").val($("#Applications").attr("value"));
if ($("#Applications").attr("value") != "")
{
$("#Machines").removeAttr("disabled");
if ($("#Machines").attr("value") != "")
{
$("#btnSearch").removeAttr("disabled");
}
else
{
$("#btnSearch").attr("disabled", "disabled");
}
}
else
{
$("#Machines").attr("disabled", "disabled");
$("#btnSearch").attr("disabled", "disabled");
}
}
function saveSelectedMachine()
{
$("#selectedMachine").val("");
$("#selectedMachine").val($("#Machines").attr("value"));
if ($("#Machines").attr("value") != "")
{
$("#btnSearch").removeAttr("disabled");
}
else
{
$("#btnSearch").attr("disabled", "disabled");
}
}
</script>
您的脚本是否在运行?脚本顶部的简单提醒? – littlechris 2009-09-22 19:58:09
你在你的global.asax文件中使用任何自定义路由吗?您在下面留下的评论与我在实施如下之前得到的错误是一样的。我相信由于我的脚本路径问题,JS运行得太早。 – littlechris 2009-09-22 20:24:41
剧本是有定位的作用在该行 $ .getJSON( “/的applicationSettings /应用/列表” 中输入功能(数据) 一个问题,如果我将其更改为\t \t \t $ .getJSON(” ../的applicationSettings /应用程序/列表“,功能(数据) 它的工作原理 我想我真的需要做的是能够正确地解决行动的路径不知道如何做到这一点在jquery 任何想法? – user99513 2009-09-22 20:58:50