O'Reilly Forums: Can Somebody Just Check To Make Sure I'm Not Doing Something Stupid Please. - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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

#1 User is offline   Dream Of Sleeping 

  • New Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 04-June 12

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

0

#2 User is offline   Beth Robson 

  • Veteran Member
  • PipPipPipPipPipPipPipPipPip
  • Group: O'Reilly Employee
  • Posts: 364
  • Joined: 17-September 08
  • 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
0

#3 User is offline   Dream Of Sleeping 

  • New Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 04-June 12

Posted 06 June 2012 - 12:22 AM

View PostBeth Robson, on 05 June 2012 - 04:21 PM, said:

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

#4 User is offline   Dream Of Sleeping 

  • New Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 04-June 12

Posted 07 June 2012 - 09:35 AM

View PostDream Of Sleeping, on 06 June 2012 - 12:22 AM, said:

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users