Page 1 of 1

Big problem with ajax to refresh webpage

Posted: Mon Feb 15, 2010 9:20 am
by gamer931215
I have a little problem with my Ajax script.
I have builded a RPG Game, and i need my ajax script to update the menu.

Now i want to script php into that ajax file, zo $username & $userid will be showed in the user's menu.
But when i script php into that file, my webpage is going to reload, and isn't going to stop, untill i remove the php code.
and then the webpage run's normally again, how can i fix this?

Greetings,
gamer

Re: Big problem with ajax to refresh webpage

Posted: Mon Feb 15, 2010 10:51 am
by socalocmatt
I'm not 100% on your question, but here are my thoughts:

The initiating page runs your javascript code that calls a php file. In your case, it appears to be a loging script. If the problem you care having is the page going to your php script when submitting the for then you need to do this (I use JQuery, so adapt it to your needs):

Code: Select all

 
<script type="text/javascript">
$("#loginFORMid").submit(funciton() {
    var uname=$("#uname").val();
    var pass=$("#pass").val();
    $.post("test.php",(user: uname,pw: pass},function(data) {
        $("#menu").replace("MENU HTML WHEN YOU WANT TO ECHO THE USER INFO"+ data +"THEN CONTINUE WITH HTML. BE SURE TO WRAP THE MENU WITH AN ID THE IS REPRESENTED BY THE '#' ");
    }
// be sure to return false
return false;
});
</script>
 
This will post the form data to the login.php script with should grab the data, login, and echo back the user info. Be sure to return false. If this isnt the issue, post your code.

Re: Big problem with ajax to refresh webpage

Posted: Mon Feb 15, 2010 11:57 am
by gamer931215
Hi,

That's not exactly the code that i'm looking for, and i ain't using code's like that in my ajax file.
I'll show you my code, hopefully you could help me solve this problem. :)

Code:

{"hp":"$hp","maxhp":"$maxhp","energy":"$energy \/ $maxenergy","enperc":100,"enopp":100,"brave":"$brave \/ $maxvrave","brperc":100,"bropp":100,"will":"100 \/ 100","wiperc":100,"wiopp":100,"username":"$username","userid":"$userid","level":"$level","levelup":"false","money":"{$fm}","cash":"{$fm}","G_energy":"100","G_nerve":"10","points":"0","diamonds":"0","merits":"0","gender":"Male","job":"3","education":1,"crons":{"cr10":"1266213603","cr15":"1266213607"},"mode":0,"mail":"0","event":"2","haspc":true,"factionname":"","factionid":"0"}

etc etc..

But now i want to script into this file, that $username must be. {$ir['username']}
I always do that like this: $username="{$ir['username']}";

But when i script this cinda code in to menu.ajax my webpage is going to reload, and when i deleted that code out my script, it's goes back to normal. How could i fix this?

Thanks

Re: Big problem with ajax to refresh webpage

Posted: Mon Feb 15, 2010 4:36 pm
by socalocmatt
Again, you will need to post your code, the entire code that is relevant to the question, the PHP and javascript.

Re: Big problem with ajax to refresh webpage

Posted: Mon Feb 15, 2010 5:18 pm
by gamer931215
This is my hole code, because if i script PHP into menu.ajax, my webpage is going to reload, automaticly and isn't going to stop..

I only have to need a way, to script php into that file, and than i can continue my work.
Hopefully you understand this :)