Posted By

qrist0ph on 03/16/09


Tagged

ajax jquery cheatSheet


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

qrist0ph
michellebracken
o0110o


jquery CheatSheet


 / Published in: HTML
 

  1. <head>
  2. <title>Titel der Webseite</title>
  3. <!-- Evtl. weitere Kopfinformationen -->
  4. <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
  5. <script type="text/javascript">
  6. function doSomething(){
  7. alert($("#username").val());
  8. $("#eineDiv").html ='<h1 id="toll">textfsfsf</h1>'
  9. }
  10.  
  11. /*
  12. * Ajax XmlHttpRequest senden
  13. */
  14. function login(){
  15. $.getJSON('/login_ajax/',{ name: $("#username").val(), password: "einPassword" }, login_callback);
  16.  
  17. }
  18. /*
  19. * Ajax Callback Funktion
  20. */
  21. function login_callback(json,text){
  22. setCookie('sessionid',json.sessionid,365);
  23. }
  24.  
  25. /*
  26. * Funktionen an bestimmte Elemente haengen
  27. */
  28. $(function () {
  29. $('.add-row').click(function() {
  30. return addForm(this, 'form');
  31. });
  32. })
  33. </script>
  34. </head>
  35. <body onload="doSomething()">
  36.  
  37. <div id="eineDiv"> Webseite</div>
  38. <input type="text" id="username" />
  39. <input type="button" name="Text 1" value="Text 1 anzeigen" onclick="login()">
  40. </body>
  41. </html>
  42. /// ------ Die login callback (mit Pyyhon) -----
  43. from django.utils import simplejson
  44. return HttpResponse(simplejson.dumps({'sessionid':request.session.session_key,'username':user.username}),status=200, mimetype='application/javascript')

Report this snippet  

You need to login to post a comment.