Hello All,

I'm trying to GET values from a DB table in JSON format through AJAX and then parse them into a JQuery List.

test.php (partial)


JSON Format it Returns:

[{"name":"1423 Peacock Haven"},{"name":"9835 Fredericksburg Rd"},{"name":"Test Project"}]

Following along with this tutorial, I'm trying to parse my own JSON above but nothing is returned in the list. I feel I may be all over the map here with errors - I'm not very familiar with AJAX as you can tell. I am also wondering if the issue is in my JSON as it does not have an object name like 'results' in the tutorial. Here is my modified code based upon the tutorial:

<script type="text/javascript">
     function appReady(){
     var ajax = new XMLHttpRequest();
          if(ajax.readyState==4 && (ajax.status==200)){
            		// Need to add UL on AJAX call or formatting of userlist is not displayed
            		$('#twitList').append('<ul data-role="listview"></ul>');
            		listItems = $('#twitList').find('ul');
            		$.each(json_results.results, function(key) {
                	html = '<center>'+json_results.results[key].name+'<center>';
            // Need to refresh list after AJAX call
            $('#twitList ul').listview();
document.addEventListener("deviceready", appReady, false);	

Note: I am retrieving the JSON differently, based upon this tutorial.

Any help you can provide pointing me in the right direction would be greatly appreciated!

Was able to finally pull correct values. Needed to modify the PHP creating the JSON to echo an object name, "results", along with the JSON members.

Now I'm just trying to simplify the code and load each value into a Jquery button. For some reason, the data will work if I'm just using regular html attributes but when I introduce Jquery Mobile UI elements, it doesn't load them. Any ideas on what I am doing wrong?

<script type="text/javascript">
		var url="http://somobetech.com/test.php";
		//initialize button
		var button = "";
		//loop through data
		$.each(json.results, function(i,project){
		button = '<a href="#" data-role="button">' + project.name + '</a>';




Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.