Search code examples
javascriptjqueryajaxhashjquery-bbq

JQuery Ajax Uncaught Type error of Of Object


I am currently using JQuery BBQ Js plugin for ajaxified navigation of my website, while I am navigating the whole site with ajax, there's one link that would show me this error.

This is my markup

<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>

All of those two links are working, but when I click the 2nd link and submit the form this error shows up when I click the other anchor tags.

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' 

That error was triggerd by this script.

$(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' );
    });

Specifically this line

 var url = $.param.fragment();

What's causing that error?

Also this is what the second link looks like..

<!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>

Solution

  • I've found the solution, the Jquery-bbq js is not being included on the Ajaxvalidation.jsp, what I did was I have included the jquery-bbq.js and its AJAX request in another JS file and both imported them if the respective page made a request