我发现我的网站存在问题,我已将它隔离到Jquery Mobile组件。我只需点击一个调用另一个PHP页面的href链接。在第二页上,我设置了一个表单和一个Jquery表单验证,用于检查SKU按钮是否被选中,如果是,它应该返回一个警报并取消表单提交。问题是,当我从第一页链接到第二页时,表单验证代码不起作用。Jquery Mobile将未知参数传递给页面
如果我刷新页面,它工作得很好。我隔离了Jquery Mobile的链接,该页面运行良好。 Jquery Mobile正在传递一些信息,使页面无法完全加载。或者,更有可能在第一页有一些结转禁用第二页上的验证代码。
我可以补充说,如果我完全在第二页(完全没有样式)摆脱到Jquery Mobile的链接,并且从第一页链接到第二页,那么Jquery Mobile格式化仍然会进行到第二个页。我已经广泛调查了这一点,我找不到任何此前提到的这个问题。我已经设置了测试页面来对此进行分类。
第1页:
<html lang="en">
<head>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1" >
<title>Customer Maintenance</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"> </script>
</head>
<body>
Test 1 page
<p><a href="test1.html">Home Page</a></p><hr>
<footer>Created by: attentionjay</footer>
</body>
</html>
<a href="test2.php" >Test Inventory</a>
第2页:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1" >
<title>Customer Maintenance</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<script>
$(function() {
$('#custalert').bind('submit', function (e) {
if($("input:first").val() == "") {
alert("You must enter a Customer Alert");
return false;
}
});
});
$(function() {
$('#queryinv').bind('submit', function (e) {
if($('#sku_checkbox').is(':checked') == true) {
alert("You must enter a SKU");
return false;
}
});
});
</script>
</head>
<body>
<div data-theme='a' >
<div style="padding:10px 20px;">
<form action="inventory_inquiry.php" method="get" id="queryinv" >
<h3>Enter SKU</h3>
<fieldset data-role="controlgroup" data-type="horizontal" data-mini="true">
<legend>Choose Input Type:</legend>
<input type="radio" data-theme="a" name="input" id="sku_checkbox" />
<label for="sku_checkbox">SKU</label>
<input type="radio" data-theme="a" name="input" id="entire_checkbox" />
<label for="entire_checkbox">Entire Inventory</label>
</fieldset>
<label for="sku" class="ui-hidden-accessible">SKU:</label>
<input type="text" name="sku" id="sku" value="" placeholder="Item SKU" data-theme="a">
<input name="customer_id" type="hidden" value='<?php echo $customer_id; ?>'/>
<button type="submit" data-theme="b">Submit</button>
</form>
</div>
</div>
<br>
<p><a href="test1.html">Home Page</a></p><hr>
<footer>Created by: attentionjay</footer>
</body>
</html>
任何帮助,我能得到将是巨大的。这对我来说是个谜。
编辑:7-1-2013 我认为这将是值得更新我在解决这个问题时发现的。禁用AJAX数据工作,但仅限于链接。我很难让它在表单提交上工作。我最终通过以下脚本全局禁用AJAX:
<script>$(document).bind("mobileinit", function(){
$.mobile.ajaxEnabled = false;
});</script>
此脚本必须放在页面上的Jquery Mobile脚本之前。这将禁用整个页面的AJAX功能。 AJAX很棒,应尽可能使用AJAX。在发现我的问题之前,我已经设置了我的网站的布局。使用Jquery Mobile功能可以更轻松地对网站进行改造。
要添加,我经常看到有'rel = “外部”'在jQuery Mobile的'href's。这也可能是一个问题,但不是100%肯定的。 –
添加data-ajax =“false”似乎工作。可以添加到表单吗?我通常从窗体调用第二页。我把这个例子作为一个测试。不过,您的解决方案确实有效。 – attentionjay
我相信它可以添加到表单中,但我不积极。我知道我曾经尝试过,但不记得它是否完美。我也看到人们使用一个小的jQuery脚本,如果他们从不在同一个文件中使用多个页面,那么它将为每个链接添加data-ajax属性。我不会推荐,但是因为那样你就限制了你使用其他jqm特性,比如Panels。 – zachmagic73