我试图使用jquery访问在多维php数组中创建的单个数据。我可以在控制台中看到数据,但是当我尝试发布数据时,Php $_POST
将返回undefined。
register.php
//put customer information in array so that it can be reused in js
$customerArray = array(
array(
'customerid' => $customerId,
'countrycode' => $countryCode,
'mobilephone' => $mobilePhoneCode
)
);
//encode in json
echo json_encode($customerArray);
jquery的
$.ajax({
type: "POST",
url: 'queries/register.php',
data: formvalues, // serializes the form's elements.
success: function(customerarr) {
console.log(customerarr);
//get customer array information
var customerID = customerarr['customerid'];
var countrycode = customerarr['countrycode'];
var mobilephone = customerarr['mobilephone'];
}
//function to send a new verification number
$('#sendnewverificationNumber').click(function(e) {
e.preventDefault();
//capture the customerid who previously signed up
var newnumberform = 'customerID=' + encodeURIComponent(customerID) +
'&countrycode=' + encodeURIComponent(countrycode) +
'&mobilephone=' + encodeURIComponent(mobilephone);
//ajax POST
$.ajax({
type: "POST",
url: 'queries/validation.php',
data: newnumberform, // serializes the form's elements.
success: function(newdata) {
console.log(newdata);
//write message
var newmsg = 'We went a new verification number to your mobile.'
//append class to make it show
$("#validationpmessage").addClass("text-success");
//display message in the modal
$("#validationpmessage").html(newmsg);
}
});
});
})