php - Prevent echo JSON from going directly to screen -
i able pass json via ajax call , put contents in , same "echo" statement returning json "echos" json directly page, don't want. how prevent happening? here code:
my form:
<script type="text/javascript" src="includes_js/registration3.js"></script>
ajax:
$.ajax({ type: "post", url: "includes_php/registration3.php", data: datastring, datatype: "json", success: function(data) { $('.message').text(data); } })
php in url:
$msgarr[] = "please enter fields"; $json_msg=json_encode($msgarr); echo $json_msg; //also sends directly page
success: function(data) { $('.message').text(data);//here magic happens, //change line want }
you have parse json: link
obj=$.parsejson(data)
and can have access keys
alert(obj.key1);
in php:
$msgarr = array("key1"=>"please enter fields"); $json_msg=json_encode(utf8_encode($msgarr)); //utf8 enconde avoid invalid format json characters strangers echo $json_msg;
Comments
Post a Comment