jQueryの.ajax関数からこのjsonを受け取りました
string(626) "[{"ID":"6032","post_author":"2276","post_date":"2011-07-27 00:00:00","post_date_gmt":"2011-07-27 00:00:00","post_content":"","post_title":"Web Developer\/Programmer","post_excerpt":"","post_status":"publish","comment_status":"closed","ping_status":"closed","post_password":"","post_name":"web-developerprogrammer","to_ping":"","pinged":"","post_modified":"2012-05-03 09:25:32","post_modified_gmt":"2012-05-03 13:25:32","post_content_filtered":"","post_parent":"4459","guid":"http:\/\/startupchile.dev\/joinastartup\/web-developerprogrammer\/","menu_order":"0","post_type":"jobman_job","post_mime_type":"","comment_count":"0"}]"
html のいくつかのパラメーターを表示するにはどうすればよいですか? たとえば、ID、post_title のみを表示しますか?
これは私のコードです:
(function($){
$('#searchjob').keypress(function(e){
var search = $.trim($(this).val());
if (e.which == "13") {
$.ajax({
beforeSend: function(){
//$('#loading').html(<img src="rutagif" alt="loading" />);
},
url:"../wp-admin/admin-ajax.php",
data:{ action: 'searching_job',data : search },
dataType: "json",
type: "POST",
success: function(data){
console.log(data);
}
});
e.preventDefault();
};
});
})(jQuery);
エラーを修正できます。PHP の json が間違っています (以前は var_dump を使用していましたが、現在は print_r を使用しています)。成功したコードを共有するだけです。
(function($){
$('#searchjob').keypress(function(e){
var search = $.trim($(this).val());
if (e.which == "13") {
$.ajax({
beforeSend: function(){
//$('#loading').html();
},
url:"../wp-admin/admin-ajax.php",
data:{ action: 'searching_job',data : search },
//dataType: "json",
type: "POST",
success: function(data){
var jsonresult = JSON.parse(data);
$.each(jsonresult, function(i, item){
alert(jsonresult[i].post_title);
});
}
});
e.preventDefault();
};
});
})(jQuery);