开发者

Disabling Ajax in JQueryMobile

I'm trying to use JQueryMobile for an POC and it seems even though I use @using (Html.BeginForm()) instead of @using (Ajax.BeginForm()), ajax is enabled by default. It is being injected from one of the script files [ ~/Scripts/jquery.mobile-1.0a2.js ].

So what I want is to simply disable the Ajax for certain forms and do full form posts. This might be pretty abvious, but i simply cant get my head around it.

A开发者_Python百科ny help is appreciated.

/BB


You have to set up the jquery mobile framework correctly to disable its auto - ajax

Here it's documented:

http://jquerymobile.com/demos/1.0a3/#docs/api/globalconfig.html


You could do something like this.

<html lang="en-us">
<head>
    <title>@ViewBag.Title</title>
    <link href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.5.min.js")" type="text/javascript"></script>

    <script language="javascript" type="text/javascript">
        $(document).bind("mobileinit", function () {
            $.mobile.ajaxFormsEnabled = @ViewBag.EnableAjax;
        });
    </script>

    <script src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js" type="text/javascript"></script>
</head>
<body>
    <div data-role="page" data-cache="never">
        <div data-role="header">
            <h1>@ViewBag.HeaderString</h1>
        </div>
        <div data-role="content">
            @RenderBody()
        </div>
        <div data-role="footer">
            <h1>HTDE</h1>
        </div>
    </div>
</body>
</html>


Just add the following line to your page, obviously you have too add this under the document.Ready() function:

$.mobile.ajaxEnabled = false;


Note: If you are using Jquery Mobile beta, the configuration parameter for disabling ajax has changed.

http://jquerymobile.com/blog/2011/06/20/jquery-mobile-beta-1-released/

"Use ajaxEnabled to globally set auto-ajax handling."

Here's a link to the documentation for beta configs: http://jquerymobile.com/demos/1.0b2/#/demos/1.0b2/docs/api/globalconfig.html

It took me way to long to figure this one out.


there is an easier way.. just figured it out from JqueryMobile documentation

http://jquerymobile.com/demos/1.0a3/#docs/api/globalconfig.html

all you have to do is,

ajaxFormsEnabled :false

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜