Ajax 呼び出しからデータを取得しました。サーバー側では、文字列を JSON にエンコードしてデータを送信します。しかし、次のようにデータを取得します
"
General abc\/def<\/h3>
dsaa<\/td> 3<\/table><\/tbody>
dfsa<\/td> 3<\/table><\/tbody>
dsdsa<\/td> 2<\/table><\/tbody><\/div>"
実際には、html 文字を表示することは想定されていません。
私はPHPとJquery ajaxを使用しています。どこで間違いを犯した可能性がありますか?
コードを更新する
function employee_deatils_search() {
global $wpdb;
$name=$_POST['user_name'];//retrive data from post array on form submitting
//main streams for a given user will be printed such a way that subjects are gruped by main stream.The order of the main streams are arranged according
//to the total of skill levels for each subject.
$stream_groupby=$wpdb->get_results("SELECT tab_subject.mai_stream, SUM( tab_skilllist.skill_level ) AS total_skill
FROM `tab_users`
JOIN tab_skilllist ON tab_skilllist.user_id = tab_users.id
JOIN tab_subject ON tab_subject.id = tab_skilllist.subject_id
WHERE tab_users.first_name = '$name' and tab_users.employ = 1
GROUP BY tab_subject.mai_stream
ORDER BY total_skill DESC");
//echo "<div id='accordion'>";
foreach($stream_groupby as $value_str){
//printing subject information, skill level and subject main stream.
//user name and main stream will be passed as arguments.
$employee_subjects=$wpdb->get_results("SELECT tab_subject.subject, tab_subject.mai_stream ,tab_skilllist.skill_level FROM `tab_users`
JOIN tab_skilllist ON tab_skilllist.user_id = tab_users.id
JOIN tab_subject ON tab_subject.id = tab_skilllist.subject_id
WHERE tab_users.first_name = '$name' and tab_subject.mai_stream = '$value_str->mai_stream'
ORDER BY tab_skilllist.skill_level desc");
//echo '<br>';
$jason = '<h3 style="font-size:15px;">';
$jason .= $value_str->mai_stream;
$jason .= '</h3>';
$jason .= '<div >';
foreach($employee_subjects as $key=> $value){
$jason .= '<table><tbody>';
$jason .= '<tr><td style="width:90%;font-size:14px;">'.$value->subject.'</td>'.'<td style="font-size:14px;">'.$value->skill_level;'</td></tr>';
$jason .= '</table></tbody>';
// echo '</br>';echo '</br>';
}
$jason .= '</div>';
}
// echo json_encode($jason) ;
//echo '</div>';
//wp_reset_query();
die();
} // end theme_custom_handler
ここにJavaScriptコードがあります
$("#sendemp").click(function(e) {
e.preventDefault();
var submit_val = $("#searchbox").val();
//alert('submitval is ' + submit_val);
$.ajax( {
type : "POST",
url : "./wp-admin/admin-ajax.php",
data : {
action : 'employee_deatils_search',
user_name : submit_val
},
success : function(data) {
// alert('hhh');
$('#accordion32').html(data);
$("tr:odd").css("background-color", "#F8F8F8");
// $( "#searchbox" ).autocomplete({
// source: data
// });
}
});
});