Javascript Jquery ajax()未按预期工作

Javascript Jquery ajax()未按预期工作,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我有一个函数getActivityHP(),我会在页面加载后立即调用它。此函数使用某些数据对另一个test3.php页面进行ajax调用,这些数据最初将包含默认值。但是,只要我添加ajax代码,函数就会停止工作,好像有错误一样。简单警报也不起作用 <script> $(document).ready( function(){ alert("Welcome");// not working getActivityHP(); } function get

我有一个函数getActivityHP(),我会在页面加载后立即调用它。此函数使用某些数据对另一个test3.php页面进行ajax调用,这些数据最初将包含默认值。但是,只要我添加ajax代码,函数就会停止工作,好像有错误一样。简单警报也不起作用

   <script>
   $(document).ready( function(){
   alert("Welcome");// not working
   getActivityHP();
   }

 function getActivityHP() {
    $("#loading").show();
    alert("Hello"); // not working 
    var search = $("#search").val();
    var deployedon = $("#deployedon").val();
    var platform = $("#platform").val();
    var country = $("#country").val();
    var carrier = $("#carrier").val();

    $.ajax({
      type: "POST",
      url: "test3.php",
      data: {
        "action"                    :   "activity",
        "deployedon"                :   deployedon,
        "platform"                  :   platform,
        "country"                   :   country,
        "carrier"                   :   carrier
    },
    success: function(msg) {
        $("#loading").hide();
        $("#activity").html(msg);

    }
    error: function() {
    alert("An error occurred while processing file.");
  }
  });

  } 
 </script>
 In my test3.php I am doing:-

 $action=$_POST['action'];
 $deployedon=$_POST['deployedon'];
 $platform=$_POST['platform'];
 $carrier=$_POST['carrier'];
 $country=$_POST['country'];


 and then I am using echo to print these in my html! 

$(文档).ready(函数(){
警告(“欢迎”);//不工作
getActivityHP();
}
函数getActivityHP(){
$(“#加载”).show();
警报(“你好”);//不工作
var search=$(“#search”).val();
var deployedon=$(“#deployedon”).val();
var platform=$(“#platform”).val();
var country=$(“#country”).val();
var carrier=$(“#carrier”).val();
$.ajax({
类型:“POST”,
url:“test3.php”,
数据:{
“行动”:“活动”,
“deployedon”:deployedon,
“平台”:平台,
“国家”:国家,
“承运人”:承运人
},
成功:功能(msg){
$(“#加载”).hide();
$(“#活动”).html(msg);
}
错误:函数(){
警报(“处理文件时出错。”);
}
});
} 
在我的test3.php中,我正在做:-
$action=$_POST['action'];
$deployedon=$_POST['deployedon'];
$platform=$_POST['platform'];
$carrier=$_POST['carrier'];
$country=$_POST['country'];
然后我使用echo在我的html中打印这些!

出现语法错误。您缺少
在-

$(document).ready( function(){
   alert("Welcome");
   getActivityHP();
});
以及在成功结束时丢失的
-

success: function(msg) {
    $("#loading").hide();
    $("#activity").html(msg);
},

更新代码并尝试运行。

此处缺少逗号:

success: function(msg) {
    $("#loading").hide();
    $("#activity").html(msg);

}, // <--- This comma
error: function() {
alert("An error occurred while processing file.");
success:函数(msg){
$(“#加载”).hide();
$(“#活动”).html(msg);

},//谢谢!进行了更改,但不幸的是仍然无法工作。您是否从test3.php中的post方法获取数据?不,我没有在那里获取数据!你检查了我的答案并更新了你的代码了吗?ajax请求工作正常吗。请检查控制台,控制台正在工作!谢谢你的帮助:)