ajax - 在 jQuery Mobile 中通过 ajax 加载带参数的 url

标签 ajax jquery parameters jquery-mobile

问题

我无法在 jQuery Mobile 中通过 Ajax 加载带参数的链接页面。 喜欢:http://www.sampleurl.com/tool.dll?name=first&more=parameters

详细信息

我正在使用 jQuery Mobile 1.0b3

我不是指带有主题标签的页内导航。我打算加载另一个网页(单独的 html 文件)。据我所知,JQM 在当前页面内搜索链接网站应该没有问题。

在某些情况下,我必须引用一个 DLL,它返回 HTML 文档作为响应。 不幸的是,我无法使用 Ajax 通过 jQuery Mobile 访问这些页面。

举个例子:我在以下网站 http://www.sampleurl.com/tool.dll?name=first&more=parameters

我想访问另一个网站,如下所示:

<a href="/tool.dll?name=second&more=parameters"> Link </a>

这不适用于启用 Ajax 的情况。我必须使用属性 rel="external" 强制非 ajax 。 是否无法通过这种方式在 JQM 中使用参数访问喜欢的内容?我想使用页面的内置加载通知。我错过了什么?

不幸的是,我还没有找到类似问题的解决方案。

代码示例

<!-- This is working, but will not get me a loading notification on mobile devices -->
<a rel="external" data-ajax="false" href="/tool.dll?name=this%20one&more=parameters">
    Link
</a>

<!-- This is not working -->
<a href="/tool.dll?&name=second&more=parameters">
    Link
</a>

<!-- Neither is this working -->
<a href="http://www.sampleurl.com/tool.dll?name=this%20one&more=parameters">
    Link
</a>

新见解(编辑)

由于某种原因,JQM 由于网站中的这一行而卡在加载页面上:

<input type="date" name="date" id="date" value="" />

问题是属性 type="date" !使用文本字段,页面可以通过 ajax 正常加载。

页面本身在 jQuery Mobile 上运行良好。日期输入只是阻止页面通过 ajax 加载。 我还没有找到解决这个问题的办法。空值属性不是问题。

最佳答案

说明

此问题与 GET 参数和 ajax 请求无关。 该问题是由 jQuery Mobile 的日期选择器插件(当包含在登陆页面中时)引起的。

如果您必须始终包含脚本,则需要通过以下方式禁用 ajax: rel="external"data-ajax="false"

解决方案

着陆页

<!-- Do not include the datepicker script in the landing page -->
<div data-role="page" id="pg_1"> 
    <div data-role="header">
        <h1>Ajax page test with date input field</h1>
    </div>

    <div id="content_div" data-role="content">
        <p>
            <a data-role="button" href="loadme.html">To the calendar</a>
        </p>
    </div>
</div>

日历页面

<head>
    <!-- include datepicker only on the target page -->
    <!-- renamed and modified version of the datepicker experiment from JQM -->
    <script type="text/javascript" src="jquery.ui.datepicker.js"></script>
    <script type="text/javascript" src="jquery-mobile-calendar.js"></script>
</head> 
<body> 
    <div data-role="page" id="pg_2"> 
        <div data-role="header">
            <h1>Ajax page test with date input field</h1>
        </div>

        <div id="content_div" data-role="content">
            <p>
                <input type="date" name="date" value="" />
                <a data-role="button" href="index.html">Back</a>
            </p>
        </div>
    </div>
</body>

关于ajax - 在 jQuery Mobile 中通过 ajax 加载带参数的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7598722/

相关文章:

jquery - 根据屏幕宽度显示或隐藏DataTables列

ios - swift 结构体作为函数参数

java - JSR168 portlet 请求在 # 符号后删除参数值

php - lastinsertId() 和第二个查询插入问题

java - 从前端应用程序查询其余后端应用程序时避免基本身份验证弹出窗口

javascript - php 中表单不完整时显示的消息

javascript - 如何使用javascript计算动态新添加的行中的列的总和?

javascript - 使用 Laravel 从 AJAX 提交中返回验证和成功的闪现消息

jquery - 与 on() 方法混淆

javascript - 将 AJAX POST 的参数传递给 Grails Controller