My question is simple I receive string and a number but only number show up How I can display both?
$.ajax({
type: "POST",
url: "data.php",
data: "act="+nr,
success: function (result) {
var arr = JSON.parse(result);
if ($.isArray(arr) == true) {
$.each(arr, function (i, n) {
$('#s_main #s_info').html("<p>+" + n + "</p>")
});
}
}
})
}); //ends here
my php:
$act = $_POST['act'];
$output =array();
$act2 = "TXT!!!";
array_push($output,$act);
echo json_encode($output);
By the way when i use append instead of html the result is correct but it will stack on and not delete the previous data
What you are getting in return is a JSON Object.
if ($.isArray(arr) == true)
This line shouldn't return true becuase an object is not an array. If the JSON.parse()
did not work it will return a value that will equate to false. So you can simply test the returned object to see if it was successful.
var jsonObj = JSON.parse(result);
if (jsonObj) {
$.each(jsonObj, function (index, value) {
$('#s_main #s_info').html("<p>+" + value + "</p>")
});
}