jQuery UI 选项卡 ajax 未从远程服务器加载
我的 MVC Razor 应用程序使用带有 Ajax 的 jQuery UI 选项卡来加载选项卡之一,当我从远程服务器访问我的应用程序与本地开发环境时,我的行为有所不同。
在本地运行,一切正常。我的选项卡调用一个控制器方法,该方法返回一个视图,并且该视图按预期呈现。
然而,当我从生产服务器上运行它时,控制器不会将任何内容返回到我的页面。我已经进行了诊断检查,并且可以验证该方法是否正在被调用,是否从数据库中提取了正确的数据,以及填充的 ViewModel 是否与控制器的“返回视图...”调用一起发送。
但是,在客户端级别,没有 HTML 被传递回 Javascript。 “警报(ui.panel.innerHTML);”下面的行仅返回加载图像 html,而不返回任何视图。
有谁知道为什么在这两种情况下行为会有所不同?
编辑:我有两个不同的远程服务器,一个开发服务器和一个证书服务器,但都不起作用。
谢谢!
Javascript:
var budgetPanelLoaded = false;
$("#tabs").tabs();
$("#tabs").bind("tabsselect", function (event, ui) {
if ($(ui.tab).text() == "Budgets") {
if (budgetPanelLoaded != true) {
$(ui.panel).append("<img id='budgetsLoadingImage' src='/images/loading.gif' width='96' height='96' />");
};
};
});
$("#tabs").bind("tabsload", function (event, ui) {
if ($(ui.tab).text() == "Budgets") {
alert(ui.panel.innerHTML);
$("#budgetsLoadingImage").remove();
budgetPanelLoaded = true;
};
});
和控制器:
Function EditOrgBudgets(ByVal Orgid As Integer) As ActionResult
Dim db As New charityContainer
Dim o As Organization
Dim ovm As OrganizationViewModel
OpenContainer(db)
'Load the organization from the database
o = (From org In db.Organizations _
Where org.Id = Orgid _
Select org).FirstOrDefault()
If (o Is Nothing) Then
'Organization doesn't exist yet
Return View("OrganizationNotCreated")
Else
'Create any empty budgets that need to be created
CreateBudgetsForOrganization(o, db)
o.OrganizationBudgets = (From ob In db.OrganizationBudgets _
Where ob.OrganizationId = o.Id _
Order By ob.Budget.Year Descending _
Select ob).ToList()
'Map it to the ViewModel
ovm = AutoMapper.Mapper.Map(Of Organization, OrganizationViewModel)(o)
Return View("OrganizationBudgets", ovm)
End If
End Function
My MVC Razor application is using jQuery UI Tabs with Ajax to load one of the tabs and I'm having different behavior when I access my application from the remote server versus my local development environment.
Running locally, everything works out fine. My tab calls a controller method which returns a view and that view is rendered as expected.
When I run it off of my production server however, nothing is returned by the controller to my page. I have put in diagnostic checks and can verify that the method is being called, the right data is being pulled from my database, and a populated ViewModel is being sent along with the "Return View..." call of my controller.
But, at the client level, there is no HTML being passed back to Javascript. The "alert(ui.panel.innerHTML);" line below only returns the loading image html and none of the view that is being returned.
Does anyone know why the behavior would be different in these two circumstances?
EDIT: I have two different remote servers, a Dev and Cert, and neither work.
Thanks!
The Javascript:
var budgetPanelLoaded = false;
$("#tabs").tabs();
$("#tabs").bind("tabsselect", function (event, ui) {
if ($(ui.tab).text() == "Budgets") {
if (budgetPanelLoaded != true) {
$(ui.panel).append("<img id='budgetsLoadingImage' src='/images/loading.gif' width='96' height='96' />");
};
};
});
$("#tabs").bind("tabsload", function (event, ui) {
if ($(ui.tab).text() == "Budgets") {
alert(ui.panel.innerHTML);
$("#budgetsLoadingImage").remove();
budgetPanelLoaded = true;
};
});
And the Controller:
Function EditOrgBudgets(ByVal Orgid As Integer) As ActionResult
Dim db As New charityContainer
Dim o As Organization
Dim ovm As OrganizationViewModel
OpenContainer(db)
'Load the organization from the database
o = (From org In db.Organizations _
Where org.Id = Orgid _
Select org).FirstOrDefault()
If (o Is Nothing) Then
'Organization doesn't exist yet
Return View("OrganizationNotCreated")
Else
'Create any empty budgets that need to be created
CreateBudgetsForOrganization(o, db)
o.OrganizationBudgets = (From ob In db.OrganizationBudgets _
Where ob.OrganizationId = o.Id _
Order By ob.Budget.Year Descending _
Select ob).ToList()
'Map it to the ViewModel
ovm = AutoMapper.Mapper.Map(Of Organization, OrganizationViewModel)(o)
Return View("OrganizationBudgets", ovm)
End If
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,Firebug 来救援了。
结果服务器返回了 500 错误,但是 jQuery 正在清除它,所以我没有看到任何东西。我必须使用 Firebug 进行调试才能看到它,这对我来说是新的(但非常酷,希望我几个月前就知道 Firebug)。
无论如何,最终的原因是我需要在我的 Linq-to-SQL 命令上使用“包含”,显然这在我的本地计算机上是不必要的(本地 SQL 可能使它变得不必要?)但是当我部署在网络中时而且 SQL 数据库是远程的,它需要这个选项。
Well, Firebug to the rescue.
Turns out the server WAS returning a 500 error, but jQuery was scrubbing that out so I didn't see anything. I had to debug with Firebug to see it, which was new to me (but very cool, wish I knew about firebug months ago).
Anyways, the ultimate cause was that I needed to use an "Include" on my Linq-to-SQL command, apparently that is not necessary on my local machine (local SQL isntance makes it unnecessary maybe?) but when I deployed in the network and the SQL databas was remote, it needed that option.
我遇到过类似的问题,并发现了这一点:
注意:
如果您使用的是 Windows2008r2(您使用的是 IIS7.5),要使任何使用 JSON 的控件正常工作,您可能需要:
安装 IIS HTTP 重定向功能(UI 已更改,因此大多数参考文献没有正确指代这是哪里)。请参阅服务器管理器、Web 角色...
运行:
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -ir
以正确注册 .NET 4 64 位IIS框架(可能需要调整v4.x版本)设置 json 的 mime 类型
如果您通过
.DataSource(dataSource 获取数据=> dataSource.Ajax(ajax => ajax.Select(
... 并且您已使用 Web 开发服务器在 VS 中运行它,请注意,当您部署到IIS。(当 Select 尝试从引用的视图获取 JsonResult 时,Fiddler 显示 IIS 返回 404.0,即使在定义了 json mime 类型之后也是如此)。解决该问题的最简单方法是在部署时将网站放在域根目录下。
I've had similar issues, and have found this:
Note:
if you're using Windows2008r2, (you're using IIS7.5), to get any controls that consume JSON to work, you may need to:
install the IIS HTTP Redirection feature (the UI has changed, so most references dont properly refer to where this is ). See Server Manager, Web Role...
run:
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -ir
to properly reg the .NET 4 64-bit framework for IIS (may need to adjust the v4.x version)setup a mime-type for json
if you're fetching data via
.DataSource(dataSource => dataSource.Ajax(ajax => ajax.Select(
... and you've got it working from within VS using the web-dev server, be aware that you will have issues when you deploy to IIS. (Fiddler reveals IIS returning 404.0 when the Select attempts to get a JsonResult from the referenced view, even after the json mime type defined). Due to the way thatajax.Select()
works.the easiest way to solve the problem is to put the website at the domain root when you deploy.