c_shelswell Posted September 4, 2009 Share Posted September 4, 2009 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 Quote Link to comment Share on other sites More sharing options...
c_shelswell Posted September 4, 2009 Author Share Posted September 4, 2009 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? Quote Link to comment Share on other sites More sharing options...
trq Posted September 4, 2009 Share Posted September 4, 2009 You might want to take a look at json_encode instead of creating json manually. Quote Link to comment Share on other sites More sharing options...
c_shelswell Posted September 5, 2009 Author Share Posted September 5, 2009 excellent that's exactly what i'll do. Thanks for the info. Love this forum somebody always knows the things you don't! Cheers Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.