Ajax调用失败。使用Jquery .ajax函数来发出简单的请求

时间:2011-05-13 01:27:58

标签: ajax jquery jquery-selectors

这是调用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'];

任何想法为什么这不起作用?谢谢!

泰勒

1 个答案:

答案 0 :(得分:1)

你没有通过回调,所以没有什么可以成功的。

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