Last active
August 29, 2015 14:25
-
-
Save devd123/4b257d645ed158d20d94 to your computer and use it in GitHub Desktop.
jquery - Parse JSON with jQuery Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************** example **************************************/ | |
var base_url = 'http://people.cs.uct.ac.za/~swatermeyer/VulaMobi/'; | |
function example() | |
{ | |
var response = ""; | |
var form_data = { | |
username: username, | |
password: password | |
}; | |
$.ajax({ | |
type: "POST", | |
url: base_url + "ajax.php?test/json", | |
data: form_data, | |
success: function(response) | |
{ | |
/*response = '[{"Language":"jQuery","ID":"1"},{"Language":"C#","ID":"2"}, | |
{"Language":"PHP","ID":"3"},{"Language":"Java","ID":"4"}, | |
{"Language":"Python","ID":"5"},{"Language":"Perl","ID":"6"}, | |
{"Language":"C++","ID":"7"},{"Language":"ASP","ID":"8"}, | |
{"Language":"Ruby","ID":"9"}]'*/ | |
console.log(response); | |
var json_obj = $.parseJSON(response);//parse JSON | |
var output="<ul>"; | |
for (var i in json_obj) | |
{ | |
output+="<li>" + json_obj[i].Language + ", " + json_obj[i].ID + "</li>"; | |
} | |
output+="</ul>"; | |
$('span').html(output); | |
}, | |
dataType: "json"//set to JSON | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment