this code submits form , id # addband.php. php inserts form data db, , echos array houses 2 arrays: 1 array of ids, other string update html select element. i've included php generates , echos arrays.
i keep getting "uncaught typeerror: cannot read property 'selectrestults' of undefined" following code. doing wrong?
javascript/jquery:
$(function() { $("#addbandform").submit(function(event) { event.preventdefault(); var globalshowid = '&id=' + window.globalshowid; $.ajax({ url: "womhscripts/addband.php", type: "post", data: $('#addbandform').serialize() + globalshowid, success: function(msg) { var actarray = msg['actidarray']; var bandarray = msg['bandselectarray']; var result = bandarray['selectresults']; window.globalshowid=''; $("#band1").html(result) }, error:function(errmsg) { console.log(errmsg); } }); }); });
addband.php
$bandselectarray = array(); $actidarray = array(); $bandresults = ""; if (isset($_post['id'])) { $showid = $_post['id']; $actsql = mysqli_query($link, "select actid act showid=".$showid.""); while($actrow = mysqli_fetch_array($actsql)) { $actidarray[] = array( 'actid' => $actrow['actid'], ); } } $selectbandsql = mysqli_query ($link, "select bandid, bandname band"); while ($row = mysqli_fetch_array($selectbandsql)) { $bandid = $row['bandid']; $bandname2 = $row['bandname']; $bandresults .= '<option value="'.$bandid.'">'.$bandname2.'</option>'; } $bandselectarray['selectresults'] = $bandresults; $resultarray = array(); $resultarray['actidarray'] = $actidarray; $resultarray['bandselectarray'] = $bandselectarray; echo json_encode($resultarray);
Comments
Post a Comment