code_junkie

jquery & php: saving some data without reload

Nov 13th, 2011
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. $("#mySpecifikButton").click(function()
  2. {
  3. ....some code here...
  4. });
  5.  
  6. <p><a id="userID">user 0</a></p>
  7. <p><a id="userID">user 1</a></p>
  8. <p><a id="userID">user 2</a></p>
  9. <p><a id="userID">user 3</a></p>
  10. ...
  11.  
  12. <input type="button" value="Button 1" id="1" />
  13. <input type="button" value="Button 2" id="2" />
  14. <input type="button" value="Button 3" id="3" />
  15. <input type="button" value="Button 4" id="4" />
  16.  
  17. <script type="text/javascript">
  18. $("input[type=button]").click(function() {
  19. $.post("myPHPscript.php",{buttonID: $(this).attr("id")},function(d) {
  20. //d is the response from the PHP page.
  21. //Do something with it!
  22. });
  23. });
  24. </script>
  25.  
  26. var xmlHttp;
  27.  
  28.  
  29. ajaxFunction(id){
  30.  
  31. url = anypage.php?Sentid=id; // here you are sending id through GET to any simple db connection mysql and php based page to add to db or anyother function.
  32.  
  33. xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true) xmlHttp.send(null)
  34.  
  35. }//end of function
  36.  
  37.  
  38. function stateChanged(){
  39. if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" ){ // any operation you want to perform here
  40.  
  41. }//end of if
  42. }//end of function
  43.  
  44.  
  45. function GetXmlHttpObject(){
  46. var xmlHttp =null;
  47. var xmlHttp =null;
  48. if (window.XMLHttpRequest){
  49.  
  50. // If IE7, Mozilla, Safari, etc: Use native object
  51. var xmlHttp = new XMLHttpRequest()
  52. }
  53. else {
  54. if (window.ActiveXObject){
  55.  
  56. // ...otherwise, use the ActiveX control for IE5.x and IE6
  57. var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  58. }
  59.  
  60. }
  61. return xmlHttp;
  62. }//end of function
  63.  
  64. <?php
  65. some_insert_function($_REQUEST["userid"], ...);
  66. ?>
  67.  
  68. function go(el) {
  69. $.post("/insert.php?items="+el.id);
  70. }
Add Comment
Please, Sign In to add comment