我有一个像下面这样的表单我需要使用 JavaScript 为每个单选按钮创建一个数组,我需要使用 Ajax 发布到 PHP 脚本
<form id="what" name="what" >
<input type="radio" name="colors" id="red" value="red" />Red<br />
<input type="radio" name="colors" id="blue" value="blue" />Blue<br />
<input type="radio" name="colors" id="green" value="green" />Green
<input type="radio" name="animals" id="dog" value="dog" />Red<br />
<input type="radio" name="animals" id="parrot" value="parrot" />Blue<br />
<input type="radio" name="animals" id="horse" value="horse" />Green
<button type="button" >send</button>
</form>
我的 Ajax 发布代码
var data = 'username=' + username + '&api_password=' + apipassword + '&sender=' + sender + '&to=' + owner + "," + mobile + '&message=' + "Name : " + name +"%0d%0a"+ "Mobile No : " + mobile +"%0d%0a"+ "Address : " + street +" "+ area + " " + formlandmark +"%0d%0a"+ "Notes : " + notes + "%0d%0a" + "Order Id : " + randomnewnewnumber + "%0d%0a" + itemstosmsdata() + '&priority=' + priority;
var adminsubmit = 'name=' + name+'&mobile='+ mobile +'&adds='+ street +" "+ area + " " + formlandmark +'¬es='+ notes+'&orderid='+ randomnewnewnumber+'&orders='+ itemstowebdata()+'&status=opened'+'&time='+time+'&date='+ dates;
$('.text').attr('disabled','true');
$('.loading').show();
$.ajax({
url: "http://something.some.com/appost.php?", // Your Sms Api Url
type: "POST",
data: data,
cache: false,
success: function (html) {
alert("Order Placed");
if (html==1) {
$('.form').fadeOut('slow');
$('.done').fadeIn('slow');
}
}
});
数据应该如下发送
radio[ { "radiobuttonename" => clicked value of the radio button},{ "radiobuttonename" => clicked value of the radio button}]