javascript - Uncaught ReferenceError: showCategory is not defined -



javascript - Uncaught ReferenceError: showCategory is not defined -

i've defined function named showcategory. however, reason debugger telling me show category not defined. , won't load/generate json pages. says "uncaught typeerror: cannot read property 'replace' of undefined"

$.ajax({ type: 'get', url: 'http://jsonstub.com/bike/1', contenttype: 'application/json', beforesend: function (request) { request.setrequestheader('jsonstub-user-key', '50caee73-c7ed-43b7-912a-7fd6fcdbfd91'); request.setrequestheader('jsonstub-project-key', '54fb5790-b2cc-432f-88ee-7d3596b700bd'); } }).done(function showcategory( urlobj, options ) { var categoryname = urlobj.hash.replace( /.*category=/, "" ), category = categorydata[ categoryname ], pageselector = urlobj.hash.replace( /\?.*$/, "" ); if ( category ) { var $page = $( pageselector ), $header = $page.children( ":jqmdata(role=header)" ), $content = $page.children( ":jqmdata(role=content)" ), markup = "<p>" + category.description + "</p><ol>", content = "<p>" + category.content + "</p>", image = "<div class='image'><img src='" + category.picurl + "'></img></div>" , citems = category.items, numitems = citems.length; ( var = 0; < numitems; i++ ) { markup += "<li>" + citems[i].name + "</li>"; } markup += "</ol>"; $header.find( "h3" ).html( category.name ); $content.html( markup + content + image ); $page.page(); $content.find( ":jqmdata(role=listview)" ).listview(); options.dataurl = urlobj.href; $.mobile.changepage( $page, options ); } }) $(document).bind( "pagebeforechange", function( e, info ) { if ( typeof data.topage === "string" ) { var u = $.mobile.path.parseurl( data.topage ), re = /^#category-item/; if ( u.hash.search(re) !== -1 ) { showcategory( u, data.options ); e.preventdefault(); } } });

i tried somethings won't work. ideas whats wrong?

demo jsfiddle

define showcategoryfunction outside of done method of ajax request , phone call it.

function showcategory(args){ //stuff } $.ajax({ //ajax stuff }).done(function(data){showcategory(argstakenfromdata)}) $(document).bind( "pagebeforechange", function( e, info ) { if ( typeof data.topage === "string" ) { var u = $.mobile.path.parseurl( data.topage ), re = /^#category-item/; if ( u.hash.search(re) !== -1 ) { showcategory( u, data.options ); e.preventdefault(); } } });

should help.

upd changed reply little bit in done function call. still errors, cause forgot define categorydata array, or don't see it's declaration, please tell in comments, so, seek out along declaring arr , tell me result.

javascript jquery json jquery-mobile

Comments

Popular posts from this blog

php - How to pass multiple values from url -

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

database - php search bar when I press submit with nothing in the search bar it shows all the data -