Jump to content


Photo

Can Somebody Just Check To Make Sure I'm Not Doing Something Stupid Please.


  • Please log in to reply
3 replies to this topic

#1 Dream Of Sleeping

Dream Of Sleeping

    New Member

  • Members
  • Pip
  • 4 posts

Posted 05 June 2012 - 06:14 AM

Hello. I'm finding this pretty frustrating. I'm used to java, and when I get an error in that I usually know what it means.

I'm on the gumball chapter and I've been trying for hours and I can't get this to work.

In google chrome I get this error..

XMLHttpRequest cannot load http://www.dreamofsl...all/sales.json. Origin http://dreamofsleeping.co.uk is not allowed by Access-Control-Allow-Origin.

I peaked ahead in the book past the cliffhanger, but it says I should be alright if both files on on the same server.

I tried the code in firefox and used the console, and I get this...

[15:04:56.447] GET http://www.dreamofsl...ball/sales.json [HTTP/1.1 200 OK 188ms]

200 means everything is OK right? But still nothing happens. I have commented out the code in the updateSales method and use an alert box instead. ONCE this worked. But then I changed something and it has never worked again.

Also is there a reason Firefox takes so long to display alterations in my source code? I upload new versions to my website, and it still displayed the old source code. Which is making this even more frustrating trying to figure out.

Here is my code. Maybe I'm just missing something really stupid. I haven't added the css file yet, as I don't see the need.

Thanks for any help. I really don't want to continue with this chapter until I get this sorted out.

<!doctype html>
<html lang="en">
    <head>
        <title>Mighty Gumball (JSON)</title>
        <meta charset="utf-8">
        <script src="mightygumball.js"></script>
    </head>
    <body>
        <h1>Mighty Gumball Sales</h1>
        <div id="sales">
        </div>
    </body>
</html>

//testing 2
window.onload = function() {
	var url = "http://www.dreamofsleeping.co.uk/gumball/sales.json";
	var request = new XMLHttpRequest();
	
	request.open("GET", url);
	request.onload = function() {
		
		if (request.status == 200) {
	        updateSales(request.responseText);
		}
	};
	
	request.send(null);
}

function updateSales(responseText) {
	 alert("in update sales"); 
	// var salesDiv = document.getElementById("sales");
	// salesDiv.innerHTML = "ResponseText = " + responseText;
}


#2 Beth Robson

Beth Robson

    Veteran Member

  • O'Reilly Employee
  • PipPipPipPipPipPipPipPipPip
  • 376 posts
  • Gender:Female
  • Location:Seattle, WA
  • Interests:I am interested in computer science, the Web, social media and the internet, Mac development, and adult learning.

Posted 05 June 2012 - 04:21 PM

Hi Dream Of Sleeping,
I just tried http://www.dreamofsl...htygumball.html and it's working fine! I see the alert.

Using Safari 5.1.7 on a Mac. No errors in the console.

Elisabeth
Elisabeth Robson
Co-founder, WickedlySmart.com
Author: Head First JavaScript Programming, Head First HTML5 Programming, Head First HTML and CSS, Head First Design Patterns

#3 Dream Of Sleeping

Dream Of Sleeping

    New Member

  • Members
  • Pip
  • 4 posts

Posted 06 June 2012 - 12:22 AM

Hi Dream Of Sleeping,
I just tried http://www.dreamofsl...htygumball.html and it's working fine! I see the alert.

Using Safari 5.1.7 on a Mac. No errors in the console.

Elisabeth


Thanks for checking. What's weird is it works fine for me now too, and I haven't changed a thing or uploaded anything to my server since I posted this.

Does it a take a while for browsers to display new content? That seems to be the case.

#4 Dream Of Sleeping

Dream Of Sleeping

    New Member

  • Members
  • Pip
  • 4 posts

Posted 07 June 2012 - 09:35 AM

Thanks for checking. What's weird is it works fine for me now too, and I haven't changed a thing or uploaded anything to my server since I posted this.

Does it a take a while for browsers to display new content? That seems to be the case.


I've found the answer to my own question. No wonder I was having difficulty with the book.

http://andrewapeters...not-your-fualt/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users