If someone could assist me please. I'm doing a jquery Ajax post, for some reason the Json object isn't working so just returning a php array instead
如果有人能帮助我,请。我正在做jquery Ajax贴子,由于某种原因Json对象不能工作,所以只返回一个php数组
$.post
(
"classes/RegisterUser.php",
$("#frmRegistration").serialize(),
function(data)
{
alert(data);
}
);
The data is returned to Javascript 100% as
数据返回到Javascript 100%。
array
(
[key]=>value
[Name] => SomeOneName
[Surname] => SomeOneSurName
)
How would i go about getting the value of Surname in Javascript?
在Javascript中如何获得姓氏的价值呢?
Thanks for your assistance? Regards
谢谢你的援助?问候
2 个解决方案
#1
3
Expanding on The MYYN's answer, after you get your script to return JSON, you must specify that you're receiving JSON and act accordingly. You can do this with .ajax()
:
扩展MYYN的答案,在得到返回JSON的脚本之后,必须指定正在接收JSON并相应地执行。您可以使用.ajax():
$.ajax({
type: 'post',
url: 'classes/RegisterUser.php',
data: $("#frmRegistration").serialize(),
dataType: 'json',
success: function(obj) {
// This alerts SomeOneSurName
alert(obj.Surname);
}
});
#2
0
Maybe your PHP script should return json (right now it seem to return something like var_dump($some_ary);
. A proper way to do this is via php's json_encode.
也许您的PHP脚本应该返回json(现在它似乎返回了var_dump($some_ary);正确的方法是通过php的json_encode。
#1
3
Expanding on The MYYN's answer, after you get your script to return JSON, you must specify that you're receiving JSON and act accordingly. You can do this with .ajax()
:
扩展MYYN的答案,在得到返回JSON的脚本之后,必须指定正在接收JSON并相应地执行。您可以使用.ajax():
$.ajax({
type: 'post',
url: 'classes/RegisterUser.php',
data: $("#frmRegistration").serialize(),
dataType: 'json',
success: function(obj) {
// This alerts SomeOneSurName
alert(obj.Surname);
}
});
#2
0
Maybe your PHP script should return json (right now it seem to return something like var_dump($some_ary);
. A proper way to do this is via php's json_encode.
也许您的PHP脚本应该返回json(现在它似乎返回了var_dump($some_ary);正确的方法是通过php的json_encode。