Jump to content

getJSON working on localhost just not online.


c_shelswell

Recommended Posts

Hi I can't figure this out. I'm populating a select box based on the selection of another. This is working fine on my machine but not online. Is there a reason this might happen.

 

my jquery on the first page:

$(function()
    {		 
	$("select#membersOrPublic").change(function()
	 {
		$.getJSON("get_categories.php",{id: $(this).val(), ajax: 'true'}, function(j)
		{
			var options = '';
			for (var i = 0; i < j.length; i++) 
			{
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			    
			    if (j[i].optionValue == 0)
			    {
				  // no results have been returned
			    }

			}

			$("select#categoryList").html(options);
		})
	})
})

 

and my get page

$cats = $db->selectFromDB('site_categories', '', "where area='".$_GET['id']."'");


if (count($cats) > 0)
{
$json = "[";

foreach ($cats as $k => $v)
{
	$json .= "{optionValue: '".$v['id']."', optionDisplay: '".$v[DEFAULT_LANG]."'},";
}

$json = substr($json, 0, -1);

$json .= "]";

echo $json;

}
else
{
$json = "[";

$json .= "{optionValue: '0', optionDisplay: 'NO CATEGORIES PLEASE CREATE ONE'}";

$json .= "]";

echo $json;

}

 

I'm not getting any errors from my get page just can't figure why it's not working online.

 

any ideas?

 

Cheers

Ok I've found what's causing it. One of the entries that is being populated is a test string of: 123456MOBcat"t"//\\''deü©ΣДçگẫ£$ which i presume is ballsing up my JSON?

 

is there a way to format this to stop if from happening?

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.