【问题标题】:Ajax call failing. Using Jquery .ajax function to make simple requestAjax 调用失败。使用 Jquery .ajax 函数发出简单的请求
【发布时间】:2011-08-24 14:06:28
【问题描述】:

这里是调用ajax函数的jquery:

   function sendAjax(type, succ){  //where succ is the success callback

   if (type=="")
   {
        $("#txtResp").empty();
        return;
   }

   if(succ === undefined) {   succ = null;  }

   switch(type)
   {
   case 'run':
       $.ajax({type:"GET",
               url: "start_mess.php",
               data: "q="+type,
               success: succ
       }); 
     break;
   }

}

这里是index.html页面内容:

    function initialLoad() 
{                   
    sendAjax('run')
    $("#txtResp").html(responseText);
}

initialLoad();

这是 PHP 页面:

echo $_GET['q'];
$q = $_GET['q'];

知道为什么这不起作用吗?谢谢!

泰勒

【问题讨论】:

  • 好吧,一方面,sendAjax('run') 后面需要一个分号。我也看不到 responseText 的定义位置。
  • 你知道 JS::onReady 技术吗? api.jquery.com/ready

标签: ajax jquery jquery-selectors


【解决方案1】:

你没有传递回调,所以没有什么可以调用成功。

试试sendAjax('run', function(data) { alert(data) });

【讨论】:

  • 简单明了的描述。正是像我这样的初学者所需要的。非常感谢
  • @Taylor 不用担心,编码愉快 :)
  • 抱歉我的回复,都是问题。我还没有评论权限:p。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-08-07
  • 2013-12-06
  • 1970-01-01
  • 2013-05-18
  • 1970-01-01
  • 2020-01-28
相关资源
最近更新 更多