我有一个这样的表格
<form id="facform" action="exec/sendfac.php" method="post">
<input id="mbr_id" class="adresse" name="facdatas[][mbr_id]" type="text" value="" readonly="readonly" />
<input id="nom" class="adresse" name="facdatas[][nom]" type="text" value="" readonly="readonly" />
<input id="adresse" class="adresse" name="facdatas[][adresse]" type="text" value="" readonly="readonly"/>
<input id="ville" class="adresse" name="facdatas[][ville]" type="text" value="" readonly="readonly"/>
<input name="facdatas[][concerne]" class="concern" value="" type="text">
<input name="ligneFac[][designation]" type="text" class="facBig" />
<input name="ligneFac[][unite]" type="text" class="facSmall" />
<input name="ligneFac[][quantite]" type="text" class="facSmall" />
<input name="ligneFac[][prixUnite]" type="text" class="facSmall" value="" />
<input name="ligneFac[][taxe]" type="text" class="facSmall" value="" />
<input name="ligneFac[][totLine]" type="text" class="facSmall" value="" />
<input id="send" type="submit" name="submit" value="Envoyer" />
此表单随此jQuery
发布$("#facform").submit(function(e)
{
var nbr_tr = $('#fac_table tr').length;
var sendURL = $(this).attr("action");
var sendPost = $(this).attr("method");
var facArray = $("#facform").serializeArray();
$.ajax(
{
method: "POST",
url: sendURL,
data: facArray,
success: function(response)
{
console.log(response);
$("#facform").submit();
}
});
});
结果给出了一个类似于每个文本的数组:
Array ( [facdatas] => Array ( [0] => Array ( [mbr_id] => 26 ) [1] => Array ( [nom] => Gautier Albert ) [2] => Array ( [adresse] => Avenue du Devin du Village 51 ) [3] => Array ( [ville] => 1406 Cronay ) [4] => Array ( [concerne] => TEST ) [5] => Array ( [totalFac] => 69.00 ) ) [ligneFac] => Array ( [0] => Array ( [designation] => Pantalon de training CPNS ) [1] => Array ( [unite] => pièces ) [2] => Array ( [quantite] => 1 ) [3] => Array ( [prixUnite] => 69 ) [4] => Array ( [taxe] => 0.00 ) [5] => Array ( [totLine] => 69.00 ) [6] => Array ( [designation] => ) [7] => Array ( [unite] => ) [8] => Array ( [quantite] => ) [9] => Array ( [prixUnite] => ) [10] => Array ( [taxe] => 0.00 ) [11] => Array ( [totLine] => 0.00 ) [12] => Array ( [designation] => ) [13] => Array ( [unite] => ) [14] => Array ( [quantite] => ) [15] => Array ( [prixUnite] => ) [16] => Array ( [taxe] => 0.00 ) [17] => Array ( [totLine] => 0.00 ) [18] => Array ( [designation] => ) [19] => Array ( [unite] => ) [20] => Array ( [quantite] => ) [21] => Array ( [prixUnite] => ) [22] => Array ( [taxe] => 0.00 ) [23] => Array ( [totLine] => 0.00 ) [24] => Array ( [designation] => ) [25] => Array ( [unite] => ) [26] => Array ( [quantite] => ) [27] => Array ( [prixUnite] => ) [28] => Array ( [taxe] => 0.00 ) [29] => Array ( [totLine] => 0.00 ) ) [submit] => Envoyer )
似乎每个字符串都是一个数组,如果我要print_r($ _ POST ['data'])它是空的......
第二个问题是如何在没有空行的情况下在php中使用这个数组?
任何想法??
感谢您的帮助
答案 0 :(得分:0)
您没有给出任何数据变量,因此它是空的。 您可以将ajax代码修改为
void setup() {
pinMode(2, INPUT);
pinMode(3, OUTPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(3, digitalRead(2));
int n = analogRead(A0);
Serial.print("analogRead from A0:");
Serial.print(n);
Serial.print("\n");
delay(100);
}
然后你可以让$ _POST ['data']包含输入。否则$ _POST只有所有输入而不是数据。