Jump to content
Killersites Forums

Use PHP, jQuery & AJAX to Load XML Data: Part 2


Woody
 Share

Recommended Posts

Hi there Ben,

Could you please tell me why my code isn't working? (I'm using xampp on my WindowsXP machine.) I have each page loaded in xampp\htdocs. The getforum page works great, but the jQuery function on the index page doesn't want to load the getforum.php. It just displays the heading, not the div. Any help in learning what I'm doing wrong would be greatly appreciated! Thanks.

 

Here is my index.php page:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

<head>

<title>Killersites</title>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

$(document).ready(function(){

$('#recentTopics').load("getforum.php");

});

</script>

</head>

<body>

 

<h1>Recent Forum Topics:</h1>

 

<div id="recentTopics"></div>

 

</body>

</html>

 

And here's my getforum.php page:

 

<?php

ini_set("display_errors",0);

$limit = 5;

$file = "http://www.killersites.com/community/index.php?/rss/forums/1-recent-community-activity/";

if ($xml = simplexml_load_file($file))

{

echo "<ul>";

foreach($xml->channel->item as $item)

{

echo "<li><a href='$item->link'>$item->title</a></li>";

$limit--;

if($limit==0){break;};

}

echo "<li><a href='http://www.killersites.com/community/index.php?app=core&module=search&do=active'>View All Topics</li></ul>";

 

}

else

{

echo "<strong>Oops! The most recent forum topics cannot be displayed at this time.</strong>";

}

?>

Link to comment
Share on other sites

I'm not seeing any issues with the code, and it works fine for me when I tested it. Just in case, are you absolutely sure your files are named correctly? For example, Windows hides the file extension by default, and there may be a slight chance your jquery file is actually named "jquery.js.js".

 

More info is here: http://www.killersites.com/community/index.php?/topic/3010-cant-open-my-website/page__gopid__16509entry16509

 

I'm not sure if your issue has anything to do with this, but it's worth checking. Also, you've double checked that Javascript is turned on in your browser, right? I would also try re-downloading the jquery file just in case as well.

Link to comment
Share on other sites

OK, Ben...I hate these weird things...thanks for your attention to my problem. When I opened my localhost this a.m. and opened index.php, it is now working as it should, with no changes made since last night! Have you any experience with this sort of behavior? It is very frustrating. I spent HOURS trying to figure out what I was doing wrong! Any light on the subject would be appreciated greatly!

Link to comment
Share on other sites

Ben...I just tried "view page source" on both browsers, and clicking on the jquery.js link in the line <script type="text/javascript" src="jquery.js"></script>. In Chrome, it opens the file...in Firefox it doesn't. Is there a way you know of that I can find out why this is? Thanks for your help. I'll just stop using firefox if I can't figure this out.

Link to comment
Share on other sites

The page just "blinked" and nothing else happened...but now it works. I opened the htdocs folder in Firefox and went to Tools > Folder Options > View, and the "Hide extensions for known file types" was already UNchecked...but under the "Manage pairs of web pages and folders" option the "Show and manage the pair as a single file" button was selected, so I changed it to "Show both parts and manage them individually". Now the page works in Firefox also.

Could you possibly explain just what that did? I haven't a clue what it is talking about, but it fixed that particular problem, or seemed to.

Link to comment
Share on other sites

Why would you add a trailing "/" to the URL? That doesn't make sense to me -- adding the "/" may make the browser think that you are looking for a index.php directory, not single file. That could potentially cause issues.

 

I can't really tell you what is going on... as I said, I only know what I see when I test the code in my browser. It works fine for me on my browser when I test it.

Link to comment
Share on other sites

Thanks Ben...Just asking the questions made me see that the trailing "/" on the url was indeed making the browser look for a directory rather than a file. I didn't realize that was what it was doing. I just always saw the trailing slash on other urls and thought it was how you did things. I'm that much of a "Newbie" you see. Anyway, thanks again...and thanks for your tutorials on the PHP section of KSU.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...