ajax response with json not working
-
hey guys i got a little problem with ajax response with json data
here is my javascript code
$("#txt-cmt").keypress(function(e) { if(e.which == 13) { var comment = $(this).val(); var message = { action: "show_comment", user_message: comment, dataType: 'json' }; $.post(ajaxUrl.url, message, function(data){ console.log(data); }); } });
when i access data like this
console.log(data);
it’s show real data like{"content":"apple"}
but when i access data like thisconsole.log(data.content)
it’s show undefined
how can i resolve this problem
here is my php code with ajax action hookadd_action("wp_ajax_show_comment", "mu_show_comment"); function mu_show_comment() { $message = isset($_POST['x']) ? $_POST['x'] : 'no message found'; $info = [ "content" => "apple" ]; echo json_encode($info); exit; }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘ajax response with json not working’ is closed to new replies.