www.webdeveloper.com
Results 1 to 6 of 6

Thread: Javascript not making a structured list

  1. #1
    Join Date
    Oct 2012
    Posts
    4

    Post Javascript not making a structured list

    Hello all,

    I got a small question wich got me stuck.

    I got a HTML page with javascript which im using to retreive a list of authors of my wordpress blogwebsite:

    HTML:
    Code:
    <div data-role="content" id="authorlist">
    <!--  A list of all the authors of the wordpress page. -->
    </div>
    Using the following JSON script:
    Code:
    <script src="http://bloggingaboutoracleapplications.org?json=get_author_index&callback=listAuthors" type="text/javascript"></script>
    Which uses the following javascript:
    Code:
    function listAuthors(data){ //Alle Authors ophalen
    			var output='<ul data-role="listview" data-filter="true">';
    			$.each (data.authors, function(key,val) {	
    			    	var tempDiv =
    			    		document.createElement("tempDiv");
    			    	tempDiv.innerHTML = val.excerpt;
    			    	$("a",tempDiv).remove();
    			    	var excerpt = tempDiv.innerHTML;
    			    	
    			    	output+='<li>';
    			    	output+='<a href="#postsFromAuthors" onclick="postsFromAuthors(' + val.id + ')" >';
    			    	output+='<h3>' + val.name + '</h3>';
    			    	output+='<p>' + val.description + '</p>';
    			    	output+='</a>';
    			    	output+='</li>';
    			    }); //Go through each author
    			    output+='</ul>';
    			    $('#authorlist').html(output);
    			}
    Which results in a nice looking author page:
    http://s8.postimage.org/7arxinxut/authorlist.png


    The following step would be to click on a person in this list and retreive all the blog posts this person has writen.

    As you could see, i call the following function for this: #postsFromAuthors"

    Which uses the following Javascript:
    Code:
    function postsFromAuthors(id){ //Alle posts ophalen van de geselecteerd author
    			var output='<ul data-role="listview" data-filter="true">';
    				$.getJSON('http://bloggingaboutoracleapplications.org/?json=get_author_posts&id=' + id + '&callback=?', 
    				function (data) {
        			$.each(data.posts,function(key,val) {
    			    	var tempDiv = document.createElement("tempDiv");
    			    	tempDiv.innerHTML = val.excerpt;
    			    	$("a",tempDiv).remove();
    			    	var excerpt = tempDiv.innerHTML;
    			    	
    			    	output+='<li>';
    			    	output+='<a href="#blogpost" onclick="showPost(' + val.id + ')">';
    			    	output+='<h3>' + val.title + '</h3>';
    			    	output+='<p>' + excerpt + '</p>';
    			    	output+='</a>';
    			    	output+='</li>';
        				
    			    	output+='</ul>';
    			    	$('#listFromAuthor').html(output);	
        				}); //Go through each post
    				});
    			}
    And the corresponding HTML:
    Code:
    <div data-role="content" id="listFromAuthor"> 
    		Attempting to load the blogposts of the selected author, please wait...<br><br> If this does not happen, please try reloading the page.
    		</div>  	<!--  Hier komen de author posts door het script onderaan de pagina. -->
    However, here comes the problem... Instead of giving me a nice list just like the first screenshot, it is giving me a list like this:
    http://s16.postimage.org/oc0n6xwxh/authorlist2.png

    Can anybody tell me what im doing wrong?

    Thank in advance...

    Zylox

  2. #2
    Join Date
    Aug 2007
    Posts
    3,767
    That's probably a CSS problem. If you look at the generated source of the page (View -> Page Source), you'll probably spot the difference between the two lists quickly.
    Great wit and madness are near allied, and fine a line their bounds divide.

  3. #3
    Join Date
    Oct 2012
    Posts
    4
    I'm sorry, but i compared them both, they use exactly the same html and css styling. It is a javascript related problem...

  4. #4
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,266
    Try this
    Code:
    function postsFromAuthors(id){ //Alle posts ophalen van de geselecteerd author
    			
    	$.getJSON('http://bloggingaboutoracleapplications.org/?json=get_author_posts&id=' + id + '&callback=?', 
    		function (data) {
        			var output='<ul data-role="listview" data-filter="true">';
        			$.each(data.posts,function(key,val) {
    			    	var tempDiv = document.createElement("tempDiv");
    			    	tempDiv.innerHTML = val.excerpt;
    			    	$("a",tempDiv).remove();
    			    	var excerpt = tempDiv.innerHTML;
    			    	
    			    	output+='<li>';
    			    	output+='<a href="#blogpost" onclick="showPost(' + val.id + ')">';
    			    	output+='<h3>' + val.title + '</h3>';
    			    	output+='<p>' + excerpt + '</p>';
    			    	output+='</a>';
    			    	output+='</li>';
        			}); //Go through each post
    			output+='</ul>';
    			$('#listFromAuthor').html(output);	
        				
    	});
    }

  5. #5
    Join Date
    Oct 2012
    Posts
    4
    @007julien

    I just tried your solution, however i still get the same view...

    http://s10.postimage.org/h2qs8mdzt/authorlist3.png

    Do you know any other solutions to this?

    p.s. if i change to code to this:
    Code:
    function postsFromAuthors(id){ //Alle posts ophalen van de geselecteerd author
    			var output='<ul data-role="listview" data-filter="true">';
    				$.getJSON('http://bloggingaboutoracleapplications.org/?json=get_author_posts&id=' + id + '&callback=?', 
    				function (data) {
        			$.each(data.posts,function(key,val) {
    			    	var tempDiv = document.createElement("tempDiv");
    			    	tempDiv.innerHTML = val.excerpt;
    			    	$("a",tempDiv).remove();
    			    	var excerpt = tempDiv.innerHTML;
    			    	
    			    	output+='<li>';
    			    	output+='<a href="#blogpost" onclick="showPost(' + val.id + ')">';
    			    	output+='<h3>' + val.title + '</h3>';
    			    	output+='<p>' + excerpt + '</p>';
    			    	output+='</a>';
    			    	output+='</li>';
        			
        				}); //Go through each post
    				});
    			    	output+='</ul>';
    			    	$('#listFromAuthor').html(output);	
        				
    				
    			}
    i do get the "layout" of the list, but no data anymore:
    http://s11.postimage.org/pnk3znizn/authorlist4.png

  6. #6
    Join Date
    Oct 2012
    Posts
    4
    Anyone? Im still stuck..

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles