Thursday, 19 September 2013

Jquery type error on cannot read property 'length' of undefined

Jquery type error on cannot read property 'length' of undefined

I am working on to change drop down menu on selection. For that I am using
jquery, ajax with json.
function ChooseGroupScript() {
$.getJSON('edit_scripts.php',
{group:$('#group').val()}, function(data) {
var select = $('#subject');
var options = select.attr('options');
$('option', select).remove();
$.each(data, function(index, array) {
options[options.length] = new
Option(array['subject']);
});
});
}
$(document).ready(function() {
ChooseGroupScript();
$('#group').change(function() {
ChooseGroupScript();
});
});
I checked in console: i am getting error like this:
Jquery type error on cannot read property 'length' of undefined
this is my PHP:
if(isset($_GET['group'])){
$currentscript = $clients->curr_group_content($_GET['group']);
$scriptscount = sizeof($currentscript);
for($i=0;$i<$scriptscount;$i++){
$subject = $currentscript[$i]['subject'];
}
}
echo json_encode($subject);

No comments:

Post a Comment