我有一个输入框简单的div来插入数据球队数据jQuery的AJAX不及格“POST”数据
<div>
<label>Register</label>
<input type="text" name="nt" placeholder="Team Name">
<label>Team</label>
<input type="text" name="n1" placeholder="Steam username">
<input type="text" name="n2" placeholder="Steam username">
<input type="text" name="n3" placeholder="Steam username">
<input type="text" name="n4" placeholder="Steam username">
<input type="submit" id="sbutton"></input>
</div>
然后使用jQuery来收集数据并将其发送到我的PHP文件。
$('#sbutton').click(function(){
var sdata=[];
$(this).parent().children("input[type=text]").each(function(index,value){
index = $(this).attr("name");
value = $(this).val();
sdata[index]=value;
});
console.log(sdata);
$.post('php/team.php',sdata,
function(returnedData){
console.log(returnedData);
});
});
在我的PHP文件,我处理这些数据,但问题是,不是由jquery的function.My PHP传递:
<?php
session_start();
include_once "functions.php";
print_r($_POST);
if(!isset($_POST["nt"])) die("Usernames not set");?>
我的控制台日志:
[nt: "asdasd", n1: "asdasd", n2: "asdasd", n3: "asdasd", n4: "asdasd"]
jquery-2.1.4.min.js:4 XHR finished loading: POST
"http://localhost/tournament/php/team.php".k.cors.a.crossDomain.send
@ jquery-2.1.4.min.js:4n.extend.ajax @ jquery-2.1.4.min.js:4n
(anonymousfunction) @ jquery-2.1.4.min.js:4(anonymous function) @ main_page.php:31n.event.dispatch @ jquery-2.1.4.min.js:3r.handle @ jquery-2.1.4.min.js:3
main_page.php:33 Array
(
)
Usernames not set
这是怎么发生的?
谢谢你工作好:) – August