Front-end page code gets multiple lines of obj
function Addbedtype () {
var obj = document.getelementsbyname (' type_name ');
var Duoxuan = ';
for (var i = 0; i < obj.length; i++) {
Duoxuan + = Obj[i].value + ', ';//If selected, add value to the variable Duoxuan
alert (Duoxuan);}
if (Duoxuan.length < 1) {
Alert (' Please add at least one item! ‘); return 0;
} else {
if (! ( Confirm (' Are you sure you want to add? ‘))) {
return false; }
}
$.ajax ({
URL: ' {: U ("Home/gat/addbedtype")} ',
Type: ' Post ',
Data: {"Duoxuan": duoxuan},//"Duoxaun" value is a string, such as {1, 2,} This type, need to parse out in the background
Success:function (data) {
Window.location.href = "/home/gat/bed"; }
}
)
}
Background Code Operations Database
Public Function Addbedtype () {
$data = Array ();
$dump = $this->seria ();
$whe [' ubid '] = $dump [' ubid '];
$whe [' add_time '] = time ();
The following is the action to parse the front-end parameters, changing the string into an array.
RTrim () is used to remove the string {"1, 2,"} to the right of the "," comma.
Explode () Changes {"" "} to an array
$x = $_post[' Duoxuan ');
$data = Explode (', ', RTrim ($x, ', '));
foreach ($data as $v) {
$whe [' type_name '] = $v;
M (' Bed_type ')->add ($whe);
}
}
PHP Front-end passed the string in the background to parse the array at the same time batch add