sql server - Ajax MSSQL query using json and php returns undefined array -
i have problem when alert( data[i].name). result undefined if array returned. knows problem is?
this javascript
$('#plus').click(function(){ $.ajax({ type : 'post', url : 'jquerydbactionview.php', datatype : 'json', data: { }, success: function( data){ $.each( data, function(i, item) { alert( data[i].name); }); } }); });
and php
$query = "select top (1) * "; $query .= "from maillist bolag = 'fal'"; $results = mssql_query($query); $result = array(); while($row = mssql_fetch_array($results)) { $result[] = array( 'id' => $row['id'], 'company' => $row['company'], 'name' => $row['name'], 'mail' => $row['mail'] ); } echo json_encode($result);
please use json.parse(data) convert json encoded result , use in each loop
Comments
Post a Comment