javascript - ajax and php flag script - set and check for cookie and work with DB -
as title states, looking flag script, explained below:
it should video site flag script: click small grey flag once, becomes colored , cannot click again. should done in ajax don't want user have page reloaded (and activity restarted) because made mistake of flagging item on site.
the php behind should not add multiple flags same user - though idea if checked cookie, if not set -> increment field in mysql , set cookie, if set ->ignore.
this urgent, total noob @ ajax , javascript , need done tuesday...
the reason need want know how it's done because project studying @ school has similar , homework think of solution accomplish same thing, without looking @ initial source code. thought of solution don't have time implement because week next one, have ton of exams , don't want miss any...
thanks in advance give me!
cheers!
make ajaxrequest, , let php handling, when done send return page.
i made template. guess can php yourself?
function setflag(state){ var ajaxrequest; // variable makes ajax possible! //set ajaxrequest major browsers, nothing here, standard try{ // opera 8.0+, firefox, safari ajaxrequest = new xmlhttprequest(); } catch (e){ // internet explorer browsers try{ ajaxrequest = new activexobject("msxml2.xmlhttp"); } catch (e) { try{ ajaxrequest = new activexobject("microsoft.xmlhttp"); } catch (e){ // went wrong alert("your browser lame!"); return false; } } } // when ajax request waits php status codes, done when reaches 4. add javascript events etc here... ajaxrequest.onreadystatechange = function(){ if(ajaxrequest.readystate < 4){ //document.getelementbyid('ajaxcatchbox').innerhtml = "load..."; } if(ajaxrequest.readystate == 4){ // javascript change flag colour image } } // here php happens without page reload. (in php file) var querystring = "?state=" + state; ajaxrequest.open("get", "thephpfilethatdoesyourdatabasehandling.php" + querystring, true); ajaxrequest.send(null); }
the php database , sets right var on 1 you'll know flag clicked. every time refresh page use var display flag clicked. when there no flag clicked yet, you'll add function , in javascript change on fly because on moment havent reloaded yet.
i added state function coz thought might want know flag clicked ofc can add id our flagnumber etc... , can send php using querystring...
gr
Comments
Post a Comment