I am trying to use jquery to update the database using .jax. It is an idea that 'user' can be enabled or disabled by setting the flag (admin) in the DB with administrator account, the script 'activate.php' just comes from entering DB.
This works, but only after clicking on the trigger three times, I am doing something wrong!
The code is as follows:
$ ('changestatus'). (Function () {var currentStatus = $ ('# activeDisp'). Attr ('value'); var activate = ""; var changeText = ""; var id = $ ('# idDisp'). Attr (' Value '' '' Disable this user; $ ('# Active Disp'). Val (active); Brake; Case "1": var active = 0; var changeText = "Enable this user"; $ ( '#activeDisp') Val (active); break;} var dataString = 'id =' + id + 'and active =' active '; $ .aex ({Type: "post", url: "activate.php" , Data: datestring, success: function (html) {$ ('. Changestatus'). Html ("& lt; a href = '#' class = 'changeStatus' & gt;" + changeText + "& lt; / a & Gt; "); // Alert (html);}}); return false;}); #activeDisp and #iddisp They are text boxes, which are inserted into PHP when the page loads.
Cheers
Update Your code should be rewritten:
$ (Function () {$ ('changestatus'). Live ('click', function () {var currentStatus = $ ('# activeDisp'). Val (); Var active = (current status == 1)? 0: 1; Var changeText = (current status == 1) "disable this user": "Enable this user" var id = $ ('# idDisp'). Val (); $ ('# ActiveDisp') .val (active); Var data string = 'id =' + id + '& amp; Active = '+ activate; $ .ense ({type: "post", url: "activate .php", data: data string, success: function (html) {$ ('changestats'). Text (changetext);}}); Return false;});}); Note: If you can set to currentStatus then return a vulue equal to active Can be less code.
Comments
Post a Comment