I have these code:
show.php:
<div id="show" style="background-color: white; color: #2b2b2b "></div>
<script>
$(document).ready(function(){
$('#btnsearch').click(function(){
var key = {
'command': 'search',
'data': $("#inputsearch").val()
};
$.ajax({
type: 'POST',
url: 'query.php',
data: key,
dataType: 'json',
success: function(msg){
$('#show').html(msg);
}
})
});
});
</script>
and query.php:
$command = $_SESSION['command'];
if($command == 'search'){
$db = Db::getInstance();
$str = $_POST['data'];
$records = $db->query("SELECT * FROM m_cinfo LEFT OUTER JOIN m_jinfo ON m_cinfo.cinfo_id=m_jinfo.cinfo_id where fullName LIKE '%$str%'");
//echo json_encode($records, JSON_UNESCAPED_UNICODE);
echo 'تست';
}
Parrams and Responce are correct and input text + search send to query.php and تست returns but nothing shows in my div. It doesn't even alert anything in the success area.
- if i uncomment echo json_encode($records, JSON_UNESCAPED_UNICODE);, is the way correct to retrieve json data?
Like i want to use the data from my db. what should i do? i get json like this:
[{"cinfo_id":"1","fullName":"علی علوی","phone":"09151234576","mail":"[email protected]","description":"در نمایشگاه آشنا شدیم","jinfo_id":"1","jobTitle":"شرکت","jobName":"بازرگانی","city":"مشهد"}]
and echo that but when i say
$('#show').html(msg.fullName);
for example, nothing would show.
Thanks in advance.
dataTypewhich is (according to documentation)the type of data that you're expecting back from the server. So your PHP should echo/print JSON instead of expecting JSON from the javascript client2.would be NO