Jump to content

getJSON


hackalive
Go to solution Solved by 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.

Edited by hackalive
Link to comment
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.

Edited by hackalive
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.