我想在ASP.net MVC2.0中使用AJAX调用来调用视图,但它不能很好地工作。这是一个AJAX方法
$.ajax({
type: 'POST',
url: '../Inventoryhealth/IHView?mac=' + val + '&name=' + val2 + '#fragment-3',
//url: '../Chart/CreateChart2?chartType=Column&a=null',
success: function (result) {
var res = result;
if (res != null && res == "1")
alert('System information can\'t be retrieved');
}
});但是如果我用这个,它就能正常工作
location.href = "../Inventoryhealth/IHView?mac=" + val + "&name=" + val2 + "#fragment-3";这是视图代码
public ActionResult IHView(String mac, string name)
{
try
{
ViewData["PollTime"] = new ClientConfigurationService().getPollTime() * 60000;
SystemInventoryService sis = new SystemInventoryService();
SystemInformation systemInfo = new SystemInformation();
systemInfo = sis.getSystemInventory(mac);
systemInfo.ChartRefreshInterval = getInterval();
systemInfo.OName = name;
bool MoreCores = true;
if (Convert.ToInt16(systemInfo.NumberOfCores) < 2)
{
systemInfo.Core1UsageDetail = "0";
systemInfo.Core2UsageDetail = "0";
MoreCores = false;
}
Add(systemInfo.ProcessorLoadPercentage, systemInfo.MemoryTotalVirtualMemorySize, systemInfo.MemoryFreeVirtualMemory, systemInfo.DrivesSize, systemInfo.DrivesTotalFreeSpace, MoreCores, systemInfo.Core1UsageDetail, systemInfo.Core2UsageDetail);
var AC = new ActiveClient();
AC.ClientMac = mac;
if (db.ActiveClients.Count() > 0)
{
db.DeleteObject(db.ActiveClients.First());
}
db.AddToActiveClients(AC);
db.SaveChanges();
if (systemInfo != null)
{
return View(systemInfo);
}
else
{
// If Healh and status can't be retrieved
// Response.Redirect("../Inventoryhealth/InventoryIndex?error=1");
return Content("1");
}
}有什么想法吗?
发布于 2011-11-25 00:29:45
我认为不使用Post,而使用Get方法。调用中没有数据选项,因此这意味着您不需要发布。我希望它能将Post更改为get。
发布于 2011-10-25 13:32:37
您可以尝试删除"..“吗?同时指定URL。THat应该可以很好地工作。您还可以使用firebug查看是否正在从服务器请求URL。
发布于 2012-01-29 12:21:19
使用jQuery的$.get而不是较低级别的$.ajax函数。在这种情况下,您希望执行http GET not a post。
尝试如下所示:
$.get('../Inventoryhealth/IHView?mac=' + val + '&name=' + val2 + '#fragment-3', function(data){
//do something on success
alert(data);
});jQuery Get
还有..。我注意到你的url中有一个哈希(#)。您需要对此进行url编码,否则将返回404。
https://stackoverflow.com/questions/7885049
复制相似问题