O'Reilly Forums: Chapter 1 help please - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Chapter 1 help please

#1 User is offline   pachec01 

  • New Member
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 25-December 06

Posted 24 February 2007 - 06:50 PM

I have completed chapter 1, but my boards.html file doesn't work the same as the one in the completed folder. All the files are in the right directory and I've proofread my script and code twice. I corrected my errors and it still doesn't work. Any clue as to what the problem might be? My boards.html file is pasted below:

<html>
<head>
<title>Boards 'R' Us</title>
<link rel="stylesheet" type="text/css" href="boards.css" />
<script type="text/javascript" src="text-util.js"> </script>
<script language="javascript" type="text/javascript">
var request = null;

function createRequest() {
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject{"Msxm12.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = null;
}
}
}

if (request == null)
alert("Error creating request object!");
}

function getBoardsSold() {
createRequest();
var url = "getUpdatedBoardSales-ajax.php";
request.open("GET", url, true);
request.onreadystatechange = updatePage;
request.send(null);
}

function updatePage() {
if (request.readyState == 4) {
var newTotal = request.responseText;
var boardsSoldEl = document.getElementById("boards-sold");
var cashEl = document.getElementById("cash");
replaceText(boardsSoldEl, newTotal);

/* Figure out how much cash Katie has made */
var priceEl = document.getElementById("price");
var price = getText(priceEl);
var costEl = document.getElementById("cost");
var cost = getText(costEl);
var cashPerBoard = price - cost;
var cash = cashPerBoard * newTotal;

/* Update the cash for the slopes on the form */
cash = Math.round(cash * 100) / 100;
replaceText(cashEl, cash);
}
}
</script>
</head>

<body>
<h1>Boards 'R' Us :: Custom Boards Report</h1>
<div id="boards">
<table>
<tr><th>Snowboards Sold</th>
<td><span id="boards-sold">1012</span></td></tr>
<tr><th>What I Sell 'em For</th>
<td>$<span id="price">249.95</span></td></tr>
<tr><th>What it Costs Me</th>
<td>$<span id="cost">84.22</span></td></tr>
</table>
<h2>Cash for the Slopes:
$<span id="cash">167718.76</span></h2>
<form method="GET">
<input value="Show Me the Money" type="button"
onClick="getBoardsSold();" />
</form>
</div>
</body>
</html>
Just because I rock doesn't mean I'm made of stone.
0

#2 User is offline   kaz 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 23-February 07
  • Location:Minnesota

Posted 12 March 2007 - 07:45 AM

It would help if you could tell us what IS happening.

Also, I'd recommend using Firefox as your browser with the Web Developer extension installed.

With these, when you page is working correctly there will be a white check mark in a green circle on the rightmost side of the Web Developer toolbar (it should keep this icon even after clicking any buttons, such as "Show Me the Money").

If it is a white exclamation mark inside of a red circle instead, click on THAT icon to bring up the Error Console. When the Error Console is up, click the clear button and close it, then immediately reload your page and check to see if you have the white check mark in the green circle, then run your test again. If you get the white exclamation mark in the red circle, take a look at the Error Console. If it says "Error: uncaught exception: Permission denied to call method XMLHttpRequest.open" you must run the html file on the same server that is running your php file.

I had that same problem. To get around that, I got a free PHP hosting account at 110mb.com and plan on upgrading to a paid account as soon as I can.
Techsplorer
[url=http://techsplorer.110mb.com/index.html]Web Developer Quest[url]
0

#3 User is offline   pachec01 

  • New Member
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 25-December 06

Posted 20 March 2007 - 07:27 PM

The working version of the page displays the following message in the row labeled "Snowboards Sold," when the Show Me the Money button is pressed:

<?php // Start with an arbitrary number of boards sold $totalSold = 1012; // Reflect new sales srand((double)microtime() * 1000000); $totalSold = $totalSold + rand(0,1000); echo $totalSold; ?>


However my version does not do anything when the button is pressed.

I appreciate your help in this matter and I look forward to your response.
0

#4 User is offline   Marten Kay 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 28
  • Joined: 29-March 07
  • Location:Melbourne, Australia

Posted 10 April 2007 - 05:55 AM

I got exactly the same result - word for word - when running the code on my computer. I quickly looked around for a free php host and found this one at XXXXXXXXXXX

author edit - recommendation removed - php site first recommended no longer able to handle load

Cheers

Marten ohmy.gif
0

#5 User is offline   marsupial_b 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 08-August 07

Posted 08 August 2007 - 08:13 AM

I am experiencing the same problem, and was trying to determine if anyone had a solution for it yet? thanks
0

#6 User is offline   tonyvh37 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 340
  • Joined: 20-May 06
  • Gender:Male
  • Location:Indiana
  • Interests:PC stuff - Gaming to Programming

Posted 09 August 2007 - 06:53 AM

you need to be running the php script on a server. You have a couple of options, 1. run a server on your computer or 2. try to find a free host that allows php support. The second would be easier to do, except for finding the host itself. The first can be done, but there is some setup involved.
0

#7 User is offline   marsupial_b 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 08-August 07

Posted 09 August 2007 - 07:12 AM

Thank you very much, I appreciate the help
0

#8 User is offline   cansweigart 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 12-August 07

Posted 12 August 2007 - 01:47 PM

After an hour or so and all the way through the chapter, how very anti-climactic to have this exercise not work when I loaded it into IE7. Because I figured it must have been a typo, I copied down all of the files from the website and tested them...nothing. When I click on the button, nothing happens. I noticed that my active-x bar was telling me that it could not load the scripts, so I told it to...still the numbers weren't updating. I tried it in Firefox, and it worked wonderfully. The only thing that I can think of is that IE7 has some sort of security problem with trying to run a .php file locally. So I grabbed the url for the php file hosted on the site. Now it works great in both Firefox and IE7. I love the book, but am very disappointed in the fact that the exercise didn't work for me without me having to debug the problem.
0

#9 User is offline   louisc 

  • Active Member
  • PipPipPipPip
  • Group: Members
  • Posts: 112
  • Joined: 12-February 07
  • Interests:human-machine interfaces

Posted 13 August 2007 - 08:10 PM

unfortunately, the book doesn't really give much explanation of php, so a lot of people are having trouble with this. here's why it wouldn't work for you in the beginning: php files have to be processed by a server before your browser gets them. so if you just put a copy in a folder on your hard drive and then try to open it, the browser will just get a text version of the script. it's almost the same as opening a plain text file with your text editor.

this is NOT like what happens when you open an html file. in that case, the browser knows how to read all your markup tags, and it can even run your javascripts because they are CLIENT-SIDE scripts, and the browser does the heavy lifting.

but with a php file, to your browser, the opening "<?php" doesn't mean anything. BUT YOUR SERVER KNOWS that everything that follows up until the closing "?>" is a bunch of code that needs to be processed before the file gets served to the browser that asked for it. that's it in a nutshell.

so, as noted earlier, there are two ways to deal with this. you can set up an account with web hosting outfit, and then upload your documents there, so they can be served to you. this is fairly easy to do, but when you are working on your files, every time you make a little change you will have to upload them again, etc.

the other way is to set up a server on your computer, and even though the files are on your local hard drive, they are actually being sent from your server to your browser. so now when you make changes all you have to do is save in your editor, then hit refresh on your browser. the problem is that setting up the server in the first place can be very frustrating.

if you want to set up a hosted account, take a look at www.110mb.com

if you want to set up a local server, on a mac, look at www.mamp.info

if you want to set up a local server on windows or linux, i'd recommend xampp from www.apachefriends.org

at this point, if you are just concentrating on AJAX, and won't be messing with the PHP files, you're probably better off with a free host.

hope this helps!
0

#10 User is offline   dada44 

  • New Member
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 10-October 07

Posted 10 October 2007 - 03:51 AM

I also get the

php // Start with an arbitrary number of boards sold $totalSold = 1012; // Reflect new sales srand((double)microtime() * 1000000); $totalSold = $totalSold + rand(0,1000); echo $totalSold;

error in the boards-complete, and nothing happening at all in my version.

I have Apache Server installed and configured in my PC, and all my PHP files are working beautifully in the folders where the boards-complete and my boards version are.

So I don't think it is a question of the PHP not working ..
Any other ideas??

Thanks in advance!
0

#11 User is offline   louisc 

  • Active Member
  • PipPipPipPip
  • Group: Members
  • Posts: 112
  • Joined: 12-February 07
  • Interests:human-machine interfaces

Posted 10 October 2007 - 10:56 AM

Well, the server is obviously not running the php script as desired, but merely returning the code in text form.

So, either php is not installed and configured properly, or something is wrong with the code.

Please post your code, and let's see if we can figure out what's going on. In the meantime, refer to my post "Chapter 1 without PHP" if you want to concentrate on the Ajax techniques, and iron out the php later.
0

#12 User is offline   dada44 

  • New Member
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 10-October 07

Posted 11 October 2007 - 03:56 AM

Im doing chapter number 2, the break neck pizza, and after typing the phone number what shows in the address field is the PHP script character by character, no an address. It happens both in my version and in the complete version.

Its exactly what happened in chapter number 1 with the boards page.
If my own PHP scripts are running and working fine when I place them in the folders where the Head Rush Ajax files are .. what's the problem? Should I change the configuration in my php.ini and/or in my Apache Server's httpd.conf ?? If so, what changes should I make?
Cannot go on with the book if its PHP scripts are not functioning.

PHP configuration and trouble shooting should have a chapter in this book, an awesome book if the PHP worked.

Thanks once again.
0

#13 User is offline   dada44 

  • New Member
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 10-October 07

Posted 11 October 2007 - 04:16 AM

I just tested it , and if I open lookupCustomer.php in the browser (Firefox 2 and IE6) it shows a customer address correctly, not the PHP script character by character as it is shown when I enter the phone number in the html form.
Hope this can give a clue.

Thanks once more.
0

#14 User is offline   louisc 

  • Active Member
  • PipPipPipPip
  • Group: Members
  • Posts: 112
  • Joined: 12-February 07
  • Interests:human-machine interfaces

Posted 11 October 2007 - 08:15 AM

ok, so now we know that php is working. if you post your code, maybe we can figure out what is wrong. remember to "Disable HTML" before you submit your post.
0

#15 User is offline   dada44 

  • New Member
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 10-October 07

Posted 12 October 2007 - 12:14 AM

Thanks for the hint louisc, but it is happening with the complete final version of both chapters that I've downloaded from this page, so it cannot be an error with the code.. otherwise everybody would be posting here an not just a few like me.

I'm guessing it has to be with PHP or Apache configuration. Just in case it helps, my Apache Server version is 2.0.59 and my PHP is php-5.2.4, both for Windows.

Thanks once again!
0

#16 User is offline   louisc 

  • Active Member
  • PipPipPipPip
  • Group: Members
  • Posts: 112
  • Joined: 12-February 07
  • Interests:human-machine interfaces

Posted 12 October 2007 - 05:42 AM

here's another shot in the dark...ithere have been problems in the past when windows users extract the downloaded files and the directories get mixed up somehow.

i'm sure you're very frustrated. problems like this suck!

maybe you can try uploading the files to another server? i have an account at 110mb.com just for experimenting around. its free and they have php enabled.
0

#17 User is offline   dada44 

  • New Member
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 10-October 07

Posted 12 October 2007 - 07:27 AM

Thanks louisc!! Everything works in 110mb.com
I would love it to work with my PHP and my Apache, but the 110mb.com solution allows me to go on with the book.
Thanks once again, you're great!!
0

#18 User is offline   cerebros 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 12
  • Joined: 18-October 08

Posted 19 October 2008 - 02:32 AM

This is definitely a PHP version/configuration issue.

I was trying to get bords.html to work on my laptop (both the version I'd done while following the examples and the version under the "\boards-complete" folder ), but was getting the
<?php // Start with an arbitrary number of boards sold $totalSold = 1012; // Reflect new sales srand((double)microtime() * 1000000); $totalSold = $totalSold + rand(0,1000); echo $totalSold; ?>
message (when it actually did anything when I clicked on the "Show me the money" button).

I then tried running the code on the server on my local network (running it locally on the server via Remote Desktop) and it worked. So I copied the contents of the PHP directory on my server and pasted it over the install on my laptop and now the straight Ajax versions work (although now I don't seem to get anything back from any of the bits of PHP I've been trying that use MySQL...).
0

#19 User is offline   hackertrang87 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 21-September 10

Posted 21 September 2010 - 04:59 AM

I don't know much about "code". Hope everyone help me "How do i fix a code 19 on my computer ?". Any help would be appreciated !



import export distributors
affiliate marketing
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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