php - Need help returning a json string after a successful jquery $.post() -


i posting php page returning following json encoded string

{"msg":"hi {{full_name}}, <br \/>\r\n<br \/>\r\n  nice meeting you."} 

i had added json object in <script> </script>

however when run $.post() , try output data.msg says undefined.

here full code

  $.post("mass_messaging.php",{template_id: template_id})          .done(function(data){              console.log(data.msg)             //outputs undefined???            }); 

below snippet of html code

<script>  addmustacheplaceholder();  {"msg":"hi {{full_name}}, <br \/>\r\n<br \/>\r\n  nice meeting you."}  </script> 

any appreciated.

you need parse json string , need object. jquery can automatically if set data type:

$.post("mass_messaging.php", {template_id: template_id}, function(){}, "json")                                                                        ^^^^^^ here 

apart not entirely clear returning. should return 1 valid json string php script , nothing else; no script tags, javascript, etc.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -