在我的代码,我有这个回调PHP压倒一切AJAX POST请求
$('#tagList').tagit({
//Every new dag will be pushed in the list array
tagsChanged: function(tagValue,action,element){
list.push(tagValue);
$.ajax({
url: "dostuff.php",
type: "POST",
data:{ items:list.join("::")},
success: function(data){
$('#wrap').append(data);
}
});
}
});
它所做的是,每次我添加一个标签新添加的标签将在阵列中推之后,它会作出AJAX发布请求。
,然后我这里有这些领域
<form method = "POST" action = "demo3.php">
News Title <input id = "news_title" type = "text" name = "news_title" /><br>
<label>Insert Some tags </label>
<ul id="tagList" data-name="demo2">
</ul>
<input type = "submit" name = "submit" id = "submit" value = "Post News" />
</div>
</form>
,当我点击提交(它基本上重新加载页面)的$ _ POST [“项目”(这是在AJAX请求,每次一个新标签创建被添加)正在擦除或删除POST全局数组中。因此将我的$ _POST全局数组留空。
无论如何我可以合并这两个?或者反正不要让PHP覆盖或删除$_POST['items']
?因为我将需要的物品为我的查询
而且我使用了一个名为TAG-IT
插件,如果你们有兴趣,这里是我整个代码
<!doctype html>
<html>
<head>
<script src="demo/js/jquery.1.7.2.min.js"></script>
<script src="demo/js/jquery-ui.1.8.20.min.js"></script>
<script src="js/tagit.js"></script>
<link rel="stylesheet" type="text/css" href="css/tagit-stylish-yellow.css">
<script>
$(document).ready(function() {
var list = new Array();
$('#tagList').tagit({
//Every new dag will be pushed in the list array
tagsChanged: function(tagValue,action,element){
list.push(tagValue);
$.ajax({
url: "dostuff.php",
type: "POST",
data:{ items:list.join("::")},
success: function(data){
$('#wrap').append(data);
}
});
}
});
});
</script>
</head>
<body>
<div id="wrap">
<div class="box">
<button class = "viewTags">View Tags</button>
<form method = "POST" action = "demo3.php">
News Title <input id = "news_title" type = "text" name = "news_title" /><br>
<label>Insert Some tags </label>
<ul id="tagList" data-name="demo2">
</ul>
<input type = "submit" name = "submit" id = "submit" value = "Post News" />
</div>
</form>
</div>
</body>
</html>
这里是dostuff。 php
<?php
$lis = $_POST['items'];
$liarray = explode("::", $lis);
print_r($liarray);
print_r($_POST);
?>
PHP不会“覆盖”$ _POST。你得到的$ _POST是PHP收到的。如果$ _POST为空,那么你没有发送任何东西,或者它的格式不正确。 – 2012-08-02 04:38:25
哦,我明白了。我将如何合并PHP收到的由ajax和POST发出的POST请求?因为我会需要他们两个。 – user962206 2012-08-02 04:39:26
这没有任何意义。你问:“我现在的奶奶发送的礼物和我从奶奶收到的礼物怎么合并?”?除非你的代码被占用,否则你的JS代码会发起一个SINGLE http请求,执行一个SINGLE POST到你的服务器端PHP脚本。 – 2012-08-02 04:40:50