我目前正在使用JQuery BBQ Js插件进行网站的导航,当我使用ajax导航整个网站时,有一个链接可以显示此错误。
这是我的标记
<ul>
<li><a id="thankyou" href="#views/thankyou.jsp">Ajaxified Thank You Message</a></li>
<li><a id="register" href="#views/ajaxvalidation.jsp">Ajaxified Register Register</a></li>
<li><a id="register" href="#views/othermessage.jsp">Ajaxified Other Message</a></li>
</ul>
所有这两个链接都有效,但当我点击第二个链接并提交表单时,当我点击其他锚标签时会出现此错误。
Uncaught TypeError: Object function (e,n){var r,i=[],s=function(e,t){t=v.isFunction(t)?t():t==null?"":t,i[i.length]=encodeURIComponent(e)+"="+encodeURIComponent(t)};n===t&&(n=v.ajaxSettings&&v.ajaxSettings.traditional);if(v.isArray(e)||e.jquery&&!v.isPlainObject(e))v.each(e,function(){s(this.name,this.value)});else for(r in e)fn(r,e[r],n,s);return i.join("&").replace(rn,"+")} has no method 'fragment'
该错误是由此脚本触发的。
$(function(){
var cache = {
'': $('.bbq-default')
};
$(window).bind( 'hashchange', function(e) {
var url = $.param.fragment();
$( 'a.bbq-current' ).removeClass( 'bbq-current' );
$( '.bbq-content' ).children( ':visible' ).hide();
url && $( 'a[href="#' + url + '"]' ).addClass( 'bbq-current' );
if ( cache[ url ] ) {
cache[ url ].show();
} else {
// Show "loading" content while AJAX content loads.
$( '.bbq-loading' ).show();
// Create container for this url's content and store a reference to it in
// the cache.
cache[ url ] = $( '<div class="bbq-item"/>' )
.appendTo( '.bbq-content' )
.load( url +"#content");//loads the content and get the div you want
}
})
$(window).trigger( 'hashchange' );
});
特别是这一行
var url = $.param.fragment();
导致该错误的原因是什么?
这也是第二个链接的样子..
<!DOCTYPE HTML>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#content').on('submit','#result',function(e){
e.preventDefault();
var data = $(this).serialize();
$.ajax({
//this is the php file that processes the data and send mail
url: "register.action",
type: "POST",
data: data,
//Do not cache the page
cache: false,
//success
success: function (html) {
$('#content').html(html);
}
});
})
})
</script>
</head>
<body>
<h3>Simple Ajax Validation.</h3>
<div id="divErrors"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<div id = "content">
<s:form action="register" id="result">
<label>UserName</label>
<s:textfield name="userBean.username" />
<s:fielderror />
<input type ="submit" id = "result_0" value="AJAX Submit" />
<!-- Test if Even Outside the main page can access the other elements -->
</s:form>
</div>
</body>
</html>
答案 0 :(得分:0)
我找到了解决方案,Jquery-bbq js没有被包含在Ajaxvalidation.jsp中,我所做的是我在另一个JS文件中包含了jquery-bbq.js及其AJAX请求,并且都导入了它们如果相应页面发出请求