Jump to content

getJSON


hackalive

Recommended Posts

Hi Guys,

 

I have an ajax script similar to this:

$.ajax({

						type: "POST",
						url: "/z/l.php",
						data: String,
						dataType: 'json',
						cache: false,
						success: function(result) {
							if(result == ''){
								
							} else {

								$("#name").val(result.name);
								$("#add").val(result.add);
								
							}

						}

					})

However add is an jsopn array like:

[{
    "Manufacturer": "Toyota",
    "Sold": 1200,
    "Month": "2012-11"
}, {
    "Manufacturer": "Ford",
    "Sold": 1100,
    "Month": "2012-11"
}, {
    "Manufacturer": "BMW",
    "Sold": 900,
    "Month": "2012-11"
}, {
    "Manufacturer": "Benz",
    "Sold": 600,
    "Month": "2012-11"
}, {
    "Manufacturer": "GMC",
    "Sold": 500,
    "Month": "2012-11"
}, {
    "Manufacturer": "HUMMER",
    "Sold": 120,
    "Month": "2012-11"
}]

However I can not get $.getJSON to work as it is not coming from a URL as result.add is already a JSON string.

 

(the $.ajax is called based on meething certain conditions during keyUp, everything else is working except the JSON string for add - I want to make it a form drop down <select>).

 

Any advice?

 

Cheers in adavnce.

Link to comment
https://forums.phpfreaks.com/topic/277637-getjson/
Share on other sites

If I changed "$("#add").val(result.add);" to alert(result.add); it would alert:

[{
    "Manufacturer": "Toyota",
    "Sold": 1200,
    "Month": "2012-11"
}, {
    "Manufacturer": "Ford",
    "Sold": 1100,
    "Month": "2012-11"
}, {
    "Manufacturer": "BMW",
    "Sold": 900,
    "Month": "2012-11"
}, {
    "Manufacturer": "Benz",
    "Sold": 600,
    "Month": "2012-11"
}, {
    "Manufacturer": "GMC",
    "Sold": 500,
    "Month": "2012-11"
}, {
    "Manufacturer": "HUMMER",
    "Sold": 120,
    "Month": "2012-11"
}]

(minus the nice formatting of course)

 

Hope that makes sense? If not please let me know.

Link to comment
https://forums.phpfreaks.com/topic/277637-getjson/#findComment-1428292
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.