Posted in PHP onDecember 19, 2012
So, your jQuery might be something like.....
$.ajax({ url: 'query.php', data: {id:10}, datatype: json success: function(results) { if (results.msg == 'success') { for (var i in data) { $('#content').append( 'id = ' + results.data[i].id + ', description = ' + results.data[i].description + ', msrp = ' + results.data[i].msrp ); } } else { $('#content').append(results.msg); } } });
And your php....
if (isset($_GET['id'])) { $sql = "SELECT id, description, msrp FROM tbl WHERE id = '{$_GET['id']}'"; $return = array(); if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $return['msg'] = 'success'; while ($row = mysql_fetch_assoc($result)) { $return['data'][] = $row; } } else { $return['msg'] = 'No results found'; } else { $return['msg'] = 'Query failed'; } header("Content-type: application/json"); echo json_encode($result); }
ajax php传递和接收变量实现思路及代码
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@