PDA

View Full Version : سوال: گرفتن اطلاعات از دیتابیس به صورت Ajax



ABZiko
شنبه 08 فروردین 1394, 15:19 عصر
سلام دوستان (ببخشید اگر جای بدی سوال پرسیدم)، این کد گرفتن اطلاعات از دیتابیس هست :


<?php

$host = "localhost";
$user = "root";
$pass = "";

$databaseName = "freakchat";
$tableName = "text";

$con = mysql_connect($host,$user,$pass);
$dbs = mysql_select_db($databaseName, $con);
$result = mysql_query("SELECT * FROM $tableName");
//fetch result
while($array = mysql_fetch_row($result)){
echo json_encode($array).'<br>';
}


?>

اومدم برای ajax، اطلاعات رو به صورت json در آوردم ...
و این هم کد های مربوط به Ajax هست :


<div id="output">this element will be accessed by jquery and this text replaced</div>
<ul class="chatText" readonly>
<script id="source" language="javascript" type="text/javascript">
$(document).ready(function(){
$(function (){
$.ajax({
url: 'Text.php',
data: "",
dataType: 'json',
success: function(data)
{
var id = data[0];
var vname = data[1];

$('#output').html("<b>id: </b>"+id+"<b> name: </b>"+vname);
}
});
});
});
</script>
</ul>


اما متسافانه ، به صورت Ajax کار نمی کنه و فقط همون کد های json رو می نویسه مثل :
this element will be accessed by jquery and this text replaced
["2","ABZiko","204576e57e27db4a27484aec0447de8b.png","Hi !","0","0"]
["3","ABZiko","204576e57e27db4a27484aec0447de8b.png","How are you?","0","0"]
["5","ABZiko","204576e57e27db4a27484aec0447de8b.png","Good !","0","0"]
["6","ABZiko","204576e57e27db4a27484aec0447de8b.png","Not Bad !","0","0"]
["12","ABZiko","204576e57e27db4a27484aec0447de8b.png","Good !","0","0"]
["13","ABZiko","204576e57e27db4a27484aec0447de8b.png","Hi !","0","0"]
["14","ABZiko","204576e57e27db4a27484aec0447de8b.png","Thanks","0","0"]
["15","ABZiko","204576e57e27db4a27484aec0447de8b.png","Good !","0","0"]
["16","ABZiko","204576e57e27db4a27484aec0447de8b.png","Thank you very much !","0","0"]
["17","ABZiko","204576e57e27db4a27484aec0447de8b.png","Hi !","0","0"]
["18","ABZiko","204576e57e27db4a27484aec0447de8b.png","I am Ali !","0","0"]
["19","ABZiko","204576e57e27db4a27484aec0447de8b.png","Thanks !","0","0"]
["20","ABZiko","204576e57e27db4a27484aec0447de8b.png","Good !","0","0"]
["21","ZikoWeb","aa274b368f4e5c096a65c9a1274a056c.png","Good !","0","0"]
["22","ABZiko","204576e57e27db4a27484aec0447de8b.png","\u0633\u0644\u0627\u0645 !","0","0"]
["23","ABZiko","204576e57e27db4a27484aec0447de8b.png","Good !","0","0"]
["24","ABZiko","204576e57e27db4a27484aec0447de8b.png","Hi !","0","0"]
["25","ABZiko","204576e57e27db4a27484aec0447de8b.png","Hi","0","0"]
["26","ABZiko","204576e57e27db4a27484aec0447de8b.png","\u0633\u0644\u0627\u0645 !!!!!","0","0"]
چی کار کنم، خواهشا کمک کنید ...

m.esmaeilzadeh
شنبه 08 فروردین 1394, 16:04 عصر
اما متسافانه ، به صورت Ajax کار نمی کنه و فقط همون کد های json رو می نویسه

مگر قراره Ajax کار خاصی بکنه ؟ response رو داره درست میاره و یعنی کار خودش رو کرده ....

ABZiko
شنبه 08 فروردین 1394, 17:26 عصر
مگر قراره Ajax کار خاصی بکنه ؟ response رو داره درست میاره و یعنی کار خودش رو کرده ....

خب مشکل اینجاست که وقتی من اطلاعات رو در textarea می نویسم و ثبت می کنم، با اینکه در پایگاه داده ثبت می شه ولی به صورت بدون لود، اونو نمایش نمی ده ...