Author Topic: Quick AJAX question  (Read 163 times)

Offline Quantz

  • Level 8
  • *
  • Posts: 36
  • Reputation: +0/-0
    • View Profile
Quick AJAX question
« on: February 15, 2012, 02:50:40 PM »
Hey I just have a quick question about AJAX and PHP include();... I'll give an explanation of what I'm trying to accomplish.

So my game template is setup so I have 2 "layout" pages included everytime a page is loaded. I have a layout_top.php and a layout_bot.php. So in essence it looks something like:

Code: [Select]
include("layout_top.php");

PAGE CONTENT

include("layout_bot.php");

My layout_top.php script contains a nav bar, and a chat. The chat runs through AJAX and is running perfect so far, updating on its own and accepting new messages with ease.

My layout_bot.php script contains details about your character with a couple bar graphs for HP/Energy/etc and then under that is a few details about the game, time/date/etc.

What I am trying to do is get the HP/Energy bars to be automaticly updated through AJAX. But everytime I try to code it, it will not work. I know its not a syntax problem, because I have rewritten it and scanned over it 15 times now.

I guess what my question is, is if I have all my AJAX calls being made in layout_top.php will they be able to update a <DIV> in layout_bot.php? I figure the answer to that is no. So I try to put my AJAX calls to update the HP/Energy bars at the top of layout_bot.php and still it wont work and I'm thinking because the headers have already been called in layout_top.php? I am not sure. If anyone could let me know and maybe give me some insight on how to solve this problem that would be much appreciated.

Cheers
« Last Edit: February 15, 2012, 02:53:03 PM by Quantz »
-- Quantz

Offline Quantz

  • Level 8
  • *
  • Posts: 36
  • Reputation: +0/-0
    • View Profile
Re: Quick AJAX question
« Reply #1 on: February 15, 2012, 03:19:36 PM »
Nevermind, I had a table in there as well and I took that out and it started working. I guess you can't have a table and a div working with the same bit of text at the same time for AJAX to work? If anyone could clear that up for me that would be great.

Cheers
-- Quantz

Offline Nox

  • Level 35
  • **
  • Posts: 767
  • Reputation: +12/-2
    • View Profile
Re: Quick AJAX question
« Reply #2 on: February 16, 2012, 02:52:19 AM »
You surely can have tables, it can be pretty much anything ... AJAX is basicly fetching the stuff you'd see by typing the url in a browser and using show source option into a variable.

It does not even have to HTML, very often a JSON is returned.

That is - what I wrote might not be absolutelly correct in every case as it is possible to determine, whether the request is an AJAX request or a normal one - so the page can return HTML for normal request and JSON for AJAX.
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal