【发布时间】:2015-08-30 11:32:09
【问题描述】:
我是 Ajax 的初学者。我想从主题表中获取数据行,它只包含一列主题为 varchar(100),在 MySQL DB 中定义。以下是我的php代码。
数据.php
<?php
$con=mysqli_connect("","root","root","DBTemp") or die("</br> Error: " .mysqli_connect_error());
$sql="select * from Subject";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_assoc($result))
{
echo $row["SUBJECT"];
//I Want This Value to Be received in my Jquery Page
//So that i can take certain action based on each Subject.
//For example creating a select box child elements,options.
}
?>
Jquery.js
$(document).ready(function()
{
var response='';
$("body").ready(function()
{
$.ajax(
{
url: '/Data.php',
type: 'GET'
success: function(text)
{
response=text;
}
});
});
$("body").append("<select> /*Get values here as options*/ </select>");
});
但所需的操作是逐行获取值,例如:- 第一行值来了-> 在 jquery 中采取某些行动; 第二行值来了-> 采取某些行动..; . . 以此类推。
【问题讨论】:
-
那么,你的 Ajax 请求在哪里???
-
@Mr.NaViD.. 哦对不起先生我的错误。让我包括那个......
-
不要在 Ajax 成功之外使用
append(),而是尝试在 Ajax 成功中使用它 -
@Mr.NaViD...先生,我试过了,它接受整张桌子作为一种选择......