/ Published in: HTML
Expand |
Embed | Plain Text
<html> <head> <!-- Parser from rom http://www.json.org/ --> <script type="text/javascript"> /* * * Pyhton REQUEST Processing * ------ * email = request.GET.get('name', False) * passwort = request.GET.get('password', False) * * Pyhton RESPONSE * ----- * return HttpResponse(simplejson.dumps({'sessionid':request.session.id}),0, mimetype='application/javascript') * */ function parseJson(){ /* * WITH eval() WORKS FINE */ var jsonString ='{ name: "Ein Name", liste: [1,"zwei",3] }'; var myObject = eval('(' + jsonString + ')'); alert("eval1 " + myObject.name + " " + myObject.liste[1]); /* * WITH eval() WORKS FINE */ var jsonString ='{ "name": "Ein Name", liste: [1,"zwei",3] }'; var myObject = eval('(' + jsonString + ')'); alert("eval2 " + myObject.name); /* * WITH JSON Parser WORKS FINE */ var jsonString ='{ "name": "Ein Name", "liste": [1,"zwei",3] }'; var myObject = JSON.parse(jsonString); alert("JSON Parser " +myObject.name); /* * WITH JSON Parser DOESNT WORK */ var jsonString ='{ name: "Ein Name", liste: [1,"zwei",3] }'; var myObject = JSON.parse(jsonString); alert("JSON Parser " +myObject.name); } /* * Ajax XmlHttpRequest senden */ function sendData(){ $.getJSON('/login_ajax/', { name: $("#username").val(), password: "einPassword" }, login_callback); } </script> </head> <body "> <input type="button" value="Json Test" onclick="parseJson()"> </body> </html>
You need to login to post a comment.
