json - 括号问题
晚安,
我怀疑
这个输出不起作用的原因[{"var1":"abc"},{"var2":"abcd"},{"var3":"abcde"}]
但这可行,
`{"var1":"abc"},{"var2":"abcd"},{"var3":"abcde"}`
中的值始终未定义
我已经尝试将此标头添加到 php 文件 header('Content-type: application/json');
但没有任何变化,警报输出ajax 代码
jQuery(document).ready(function(){
jQuery("btn").click(function(){
jQuery.ajax({
dataType: 'json',
url: "file.php",
success: function(json){
send = "first: " + json.var1+ "\n";
send += "second: " + json.var2";
alert(send);
}
});
});
});
good night
i have a doubt
what reason this output doesn't work [{"var1":"abc"},{"var2":"abcd"},{"var3":"abcde"}]
but this works
`{"var1":"abc"},{"var2":"abcd"},{"var3":"abcde"}`
i already try add this header to the php file header('Content-type: application/json');
but nothing change, the values are always undefined in the alert output
ajax code
jQuery(document).ready(function(){
jQuery("btn").click(function(){
jQuery.ajax({
dataType: 'json',
url: "file.php",
success: function(json){
send = "first: " + json.var1+ "\n";
send += "second: " + json.var2";
alert(send);
}
});
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的第一个在数组中包含对象,要访问它们,您需要执行...
...等等。
您的
success
回调中还有一个尾随的"
。Your first one has the objects in an array, to access them you would need to do...
...and so on.
You also have a trailing
"
in yoursuccess
callback.