我是从我的Ajax响应得到的[对象的对象。
I'm getting an [object object] from my ajax response.
$.ajax({
type: "GET",
data: "id_1="+id_1+"&id_2="+id_2,
url:"ajax/url.php"
}).done(function(data){
var left= $(data).find("#left");
$("#left").html(left);
alert(left);
});
在我的网址,我只是有一个简单的编码
In my url, I just have a simple coding
if(isset($_GET["id_1"]) && isset($_GET['id_2'])){
$id_1 = $_GET["id_1"];
$id_2 = $_GET['id_2'];
$right= $dbh->prepare("SELECT COUNT(*) FROM table WHERE id_1 = ?");
$right->execute(array($id_1));
$left= $dbh->prepare("SELECT COUNT(*) FROM table WHERE id_1 = ? ");
$left->execute(array($id_2));
<div id='right'><?php echo $right->fetchColumn();?></div>
<div id='left'><?php echo $left->fetchColumn();?></div>
}
当我这是所有做的,它提醒回来[对象的对象]
When I this is all done, it alerts back [object object]
谁知道它为什么呢?
谢谢!
编辑:
我添加了一些编码在.done(函数())
I added some coding in the .done(function())
我已经解决了我的问题。问题是,我需要在另一个缠上了我的div的。在这以后,find()方法将能够捕捉那些ID的,并返回适当的对象。
I Have solved my problem. The issue was that I needed to wrap my div's within another . After that the find() method would be able to capture those id's and return the proper objects.
if(isset($_GET["id_1"]) && isset($_GET['id_2'])){
$id_1 = $_GET["id_1"];
$id_2 = $_GET['id_2'];
$right= $dbh->prepare("SELECT COUNT(*) FROM table WHERE id_1 = ?");
$right->execute(array($id_1));
$left= $dbh->prepare("SELECT COUNT(*) FROM table WHERE id_1 = ? ");
$left->execute(array($id_2));
<div> // wrapper
<div id='right'><?php echo $right->fetchColumn();?></div>
<div id='left'><?php echo $left->fetchColumn();?></div>
</div>
}