我有一个函数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!
答案 0 :(得分:1)
存在语法错误。你错过了)
-
$(document).ready( function(){
alert("Welcome");
getActivityHP();
});
在成功结束时遗失,
-
success: function(msg) {
$("#loading").hide();
$("#activity").html(msg);
},
更新您的代码并尝试运行。
答案 1 :(得分:0)
你在这里错过了一个逗号:
success: function(msg) {
$("#loading").hide();
$("#activity").html(msg);
}, // <--- This comma
error: function() {
alert("An error occurred while processing file.");