php - jquery 类型错误 : Response is null

标签 php javascript jquery linux apache

下面的代码返回 JavaScript 错误:TypeError:响应为 null

注意:它在我的本地计算机 WAMP 上工作正常,但在实时 LINUX 主机上失败。

有什么想法吗?

JQUERY

$(document).ready(function()
{
   $("#run").click(function(event)
   {
      $('#run').hide();
      $('#loader').fadeIn(1000);

      $.ajax(
      {
         type       : 'POST',
         url        : 'process.php',
         data       : 'name=jolly&surname=fish',
         dataType   : 'json',
         success    : function(response)
         {
             $('#loader').stop(true).fadeOut(function ()
             {
                  if (response.status == 'goodjob')
                  {
                      $('#tick').fadeIn(1000, function ()
                      {
                          $('#script').fadeIn(1000);
                      });
                  }
                  else
                  {
                      $('#cross').fadeIn(1000);
                  }
              });
          },
          error: function (jqXHR, textStatus, errorThrown)
          {
              alert(textStatus + '---' + errorThrown);
          }
      });
   });
});

HTML

<div id="first">
   <img id="run" src="run.png" />
   <img id="loader" src="loader.png" style="display:none;" />
   <img id="success" src="success.png" style="display:none;" />
   <img id="fail" src="fail.png" style="display:none;" />
</div>
<div id="next" style="display:none;">
   ....
   ....
</div>

PHP

<?php echo json_encode(array('status' => 'goodjob')); ?>

来自 FIREBUG 的详细信息

--- 标题

Response Headers
Cache-Control   no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection  Keep-Alive
Content-Length  0
Content-Type    text/html; charset=UTF-8
Date    Thu, 30 Aug 2012 13:33:41 GMT
Expires Thu, 19 Nov 1981 08:52:00 GMT
Pragma  no-cache
Proxy-Connection    Keep-Alive
Server  Apache/2.2.3 (Red Hat)
X-Powered-By    PHP/5.1.6

Request Headers
Accept  application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Cache-Control   no-cache
Content-Length  27
Content-Type    application/x-www-form-urlencoded; charset=UTF-8
Cookie  MoodleSession=7uck9j6n2ff7r9vc63tvt85t43; MoodleSessionTest=q0Ywtc2psj; MOODLEID_=%25E2%25C8%2513E%25BD
Host    192.168.10.11
Pragma  no-cache
Proxy-Connection    keep-alive
Referer http://192.168.10.11/portal/update-database/index.php
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1
X-Requested-With    XMLHttpRequest

--- 发布

Parameters application/x-www-form-urlencoded
name jolly
surname fish

Source
name=jolly&surname=fish

最佳答案

从你的 php 文件返回

$status = 'goodjob';
echo $status;

在你的 Jquery 中

success    : function(response)
{
   if(response == 'goodjob')
   //what you want todo
}

关于php - jquery 类型错误 : Response is null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12198567/

相关文章:

php - 在 AJAX 和 PHP 的另一个选项卡中提交表单并显示文本框值

PHPMyAdmin 在 Debian 上安装时不要求输入 Mysql 密码

php - 通过 unserialize() 函数和 mysql 查询获取所有数组值

php - INSERT INTO 失败且没有错误

javascript - 显示/隐藏文本 JavaScript 错误

javascript - 在 ReactJS 中的 SVG 顶部显示用户的姓名缩写

javascript - 从元素复制 HTML,用 jQuery 替换文本,然后附加到元素

javascript - 无法从 .json 文件加载 json 数据

javascript - jQuery Find() 和 XML 在 IE 中不起作用

javascript - 在另一个函数完成 JavaScript 和 JQuery 后运行函数