logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > Javascript and JS frameworks
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 12-17-2010, 04:13 PM   #1
Adam_C
 
Join Date: Feb 2009
Posts: 129
Default load multiple js ajax functions onload

Hi, does anyone know the most efficient way of calling multiple functions (which load xml pages (they work fine seperately)) when the pages loads?

I have tried putting all the functions in one function then only calling that but it doesn't load the xml content?

thanks a lot
__________________
http://adamscarter.co.uk/
Adam_C is offline   Reply With Quote
Old 12-17-2010, 04:26 PM   #2
ranjan
 
Join Date: Dec 2004
Posts: 405
Default Show me the code

Cant help without seeing whats done
ranjan is offline   Reply With Quote
Old 12-17-2010, 04:29 PM   #3
Adam_C
 
Join Date: Feb 2009
Posts: 129
Default

Quote:
Originally Posted by ranjan View Post
Cant help without seeing whats done
both js files i use are here:
http://daily.adamscarter.co.uk/js/newsSection.js
http://daily.adamscarter.co.uk/js/photosSection.js

i want to load both the 'loadNews(0)' and 'loadPhotos()' when the page loads
__________________
http://adamscarter.co.uk/
Adam_C is offline   Reply With Quote
Old 12-17-2010, 06:08 PM   #4
ranjan
 
Join Date: Dec 2004
Posts: 405
Default Still cannot help you

I really cannot help if I just look at the functions.

I need to see where the function calls are made.

Most common way of debugging ajax calls is as below:

1. when data is recd. (ready state) log the xml to your console. this will show you if your data is fetched as expected.

2. make sure you begin to populate html only when the data is recd and not before (delays are expected of server that sends data)
ranjan is offline   Reply With Quote
Old 12-17-2010, 06:13 PM   #5
Adam_C
 
Join Date: Feb 2009
Posts: 129
Default

Quote:
Originally Posted by ranjan View Post
I really cannot help if I just look at the functions.

I need to see where the function calls are made.

Most common way of debugging ajax calls is as below:

1. when data is recd. (ready state) log the xml to your console. this will show you if your data is fetched as expected.

2. make sure you begin to populate html only when the data is recd and not before (delays are expected of server that sends data)
I simply just made a new js page, made a function within there called 'onPageLoad' then put the functions to load, in there.

I then attached the js to the main php page, then called that function called 'onPageLoad' in the body tag, in the 'onload' attribute.
__________________
http://adamscarter.co.uk/
Adam_C is offline   Reply With Quote
Old 12-17-2010, 06:56 PM   #6
ranjan
 
Join Date: Dec 2004
Posts: 405
Default

no page url? sorry cant help

but this is how i would do it using jquery and yql

Code:
<div id="bbcNews"></div>
	<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
	<script>
	var urlBBCUK = 'http://query.yahooapis.com/v1/public/yql?q=select%20title%2C%20description%2C%20link%20from%20rss%20where%20url%3D%22http%3A%2F%2Ffeeds.bbci.co.uk%2Fnews%2Fuk%2Frss.xml%22&format=json&diagnostics=true';
	$.ajax({
		url: urlBBCUK,
		dataType: "jsonp",
		success: function(data) {
			var newsItems = data.query.results.item;
			var ml = [];
			for(var i=0, l=newsItems.length; i<l; i++){
				var tmpML = '<div class="item"><h3><a href="'+newsItems[i].link+'">'+newsItems[i].title+'</a></h3><p>'+newsItems[i].description+'</p></div>';
				ml.push(tmpML);
			}
			$('#bbcNews').html(ml.join(''))
		}
	}); 
	</script>
ranjan is offline   Reply With Quote
Old 12-17-2010, 07:09 PM   #7
Adam_C
 
Join Date: Feb 2009
Posts: 129
Default

my page url is simply: daily.adamscarter.co.uk and i use a proxy instead of yql, i used daily.adamscarter.co.uk/proxy.php
__________________
http://adamscarter.co.uk/
Adam_C is offline   Reply With Quote
Old 12-17-2010, 08:26 PM   #8
ranjan
 
Join Date: Dec 2004
Posts: 405
Default

Question: Since you are already using jquery, I was wondering why are you not using jquerys ajax methods and write your own?

If you use jquery xml parsing is easier

Code:
$.ajax({
		url: 'http://daily.adamscarter.co.uk/proxy.php?url=http://feeds.bbci.co.uk/news/" + categories[categoryNumber] + "/rss.xml',
		dataType: "xml",
		success: function(xml) {
                    $(xml).find("item").each(function(){
                       var eachItem = $(this);
                       console.log(eachItem)
                    });
		}
	});
ranjan is offline   Reply With Quote
Old 12-17-2010, 09:13 PM   #9
Adam_C
 
Join Date: Feb 2009
Posts: 129
Default

ok thanks, in answer to your question literally this website has been my first using jquery and i am trying to learn it, thanks again for the pointer
__________________
http://adamscarter.co.uk/
Adam_C is offline   Reply With Quote
Old 12-17-2010, 10:22 PM   #10
ranjan
 
Join Date: Dec 2004
Posts: 405
Default

No worries, ask if you get stuck
ranjan is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:05 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com