Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP将JSON返回到JQUERY AJAX调用_Php_Json_Jquery - Fatal编程技术网

PHP将JSON返回到JQUERY AJAX调用

PHP将JSON返回到JQUERY AJAX调用,php,json,jquery,Php,Json,Jquery,我仍然在努力了解JQUERY、AJAX和PHP的内部和外部 我现在可以调用PHP OK,处理表单元素并发送电子邮件,但我不会处理返回AJAX的操作。我总是得到错误:选择器被激活,当我试图列出假定返回的JSON时,我得到了信息,这显然是错误的 假设返回JSON的PHP <?php touch('phpTouch.txt'); // process email $email=1; if ($email) { $value = array('return' => 1, 'msg1

我仍然在努力了解JQUERY、AJAX和PHP的内部和外部

我现在可以调用PHP OK,处理表单元素并发送电子邮件,但我不会处理返回AJAX的操作。我总是得到
错误:
选择器被激活,当我试图列出假定返回的JSON时,我得到了信息,这显然是错误的

假设返回JSON的PHP

<?php

touch('phpTouch.txt');
// process email
$email=1;
if ($email) {
    $value = array('return' => 1, 'msg1' => 'Message sent OK, we will be in touch ASAP');
} else {
    $value = array('return' => 0, 'msg1' => 'Message Failed, please try later');
}
$output = $json->encode($value);
echo $output;

?>

如果有人能告诉我犯了什么愚蠢的错误,我将不胜感激。

您可以通过以下方式返回PHP中的json:

header('Content-Type: application/json');
echo json_encode(array('foo' => 'bar'));
exit;

$json
在哪里定义?您只需使用
json_encode()您使用的jQuery版本是什么?@marc谷歌版1.6.2CDN@Prisoner. 我同意你的建议。我显然错了。再次复制了代码,但仍然没有像我希望的那样工作-相同的伪值列表应该是输出状态=。。。有什么价值?谢谢你的提示。我试过了,我得到了同样的结果。为什么总是执行
错误:
?非常感谢。我现在明白为什么了,你是对的。现在修复并工作了我添加了
exit
,因为JSON响应后应该没有任何内容,希望您不介意。
readyState=4
setRequestHeader=function (a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this}
getAllResponseHeaders=function (){return s===2?n:null}
getResponseHeader=function (a){var c;if(s===2){if(!o){o={};while(c=bF.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c}
overrideMimeType=function (a){s||(d.mimeType=a);return this}
etc etc 
header('Content-Type: application/json');
echo json_encode(array('foo' => 'bar'));
exit;