开发者

jQuery UI Tabs ajax not loading from remote server

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' />");
            };
        };
    });开发者_StackOverflow

    $("#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


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.


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 that ajax.Select() works.

the easiest way to solve the problem is to put the website at the domain root when you deploy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜