Author Topic: Hello i need help with ajax  (Read 740 times)

Offline Aliss

  • Level 9
  • *
  • Posts: 54
  • Reputation: +1/-1
    • View Profile
Hello i need help with ajax
« on: August 28, 2009, 02:37:53 PM »
I have problem with ajax page refresh. I tryed many ways to to run ajax in subpages but simply javascript is not working normaly.

MAYBE someone of you could help me to make that.

I attached source my work.
« Last Edit: August 28, 2009, 03:04:16 PM by Aliss »

Offline Tribal

  • Level 22
  • *
  • Posts: 256
  • Reputation: +1/-1
    • View Profile
Re: Hello i need help with ajax
« Reply #1 on: August 28, 2009, 02:48:19 PM »
Heya,

Is it possible to get a few more files in that RAR?

Ideally the config file (which contains config for all the javascript variables etc and the stylesheet if possible?

(you might want to remove your database password from the main.php file as well before too many people download it XD)

Also, i am not 100% sure what you are trying to achieve. Do you mean you cannot execute JavaScript from a page that has been loading by the ajax?
« Last Edit: August 28, 2009, 03:01:38 PM by Tribal »

Offline Aliss

  • Level 9
  • *
  • Posts: 54
  • Reputation: +1/-1
    • View Profile
Re: Hello i need help with ajax
« Reply #2 on: August 28, 2009, 03:08:53 PM »
<a href=\"JavaScript:ajax('GET','main.php?op=battle','page','1')\">Battle</a> this how i call page what i need. But my problem is that whana refresh this ajax('GET','main.php?op=battle','page','1') function in my battle page again after some time but i can't get to work that.

Offline Tribal

  • Level 22
  • *
  • Posts: 256
  • Reputation: +1/-1
    • View Profile
Re: Hello i need help with ajax
« Reply #3 on: August 28, 2009, 03:40:37 PM »
Found the solution.

Basically when you load the content via ajax, you then insert it into the div (using div.innerHTML = response), this is what you have been doing all along.

After having done that you then need to loop through the div and search for all <script> tags that were inserted from the AJAX response. After this you need to execute, eval(), the contents of these script tags.

I have modified your ajax.js and have tested it in ie 7 + 8, ff, safari and chrome and it is all working for me.

See the ajax.js file attached

Offline Aliss

  • Level 9
  • *
  • Posts: 54
  • Reputation: +1/-1
    • View Profile
Re: Hello i need help with ajax
« Reply #4 on: August 28, 2009, 04:23:56 PM »
Ths for help now javascript works but i run in another problem

Code: [Select]
if ($battle['status'] == 1){?>
<script language="javascript" type="text/javascript">
function a(){
ajax('POST','main.php?op=battle&id=1','page','1');
setTimeout("a()", 10000);
}
a();
</script>
<?
}
i use in my battle page to refresh it but he refresh page every second but i set to refresh after 10s. How to fix this now.

Offline Tribal

  • Level 22
  • *
  • Posts: 256
  • Reputation: +1/-1
    • View Profile
Re: Hello i need help with ajax
« Reply #5 on: August 28, 2009, 04:30:22 PM »
Hmm. Try this:

Code: [Select]
<script language="javascript" type="text/javascript">
setInterval(function() {
ajax('POST','main.php?op=battle&id=1','page','1');
}, 10000);
</script>

Lemmie know how it goes.
« Last Edit: August 28, 2009, 05:41:56 PM by Tribal »

Offline Aliss

  • Level 9
  • *
  • Posts: 54
  • Reputation: +1/-1
    • View Profile
Re: Hello i need help with ajax
« Reply #6 on: August 28, 2009, 04:57:57 PM »
Thx very much it works noe like a charm :D

Offline Tribal

  • Level 22
  • *
  • Posts: 256
  • Reputation: +1/-1
    • View Profile
Re: Hello i need help with ajax
« Reply #7 on: August 28, 2009, 05:43:16 PM »
Ha Ha.

No worries. Best of luck with the game.

When I first started doing AJAX I had the exact same problem, took me a good few hours to get a working solution. So simple when you look back at it though :)

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal