话不多说,直接贴代码
$
(
'.ajax-post'
).
click
(
function
(){
var
form_data
=
$
(
'form'
).
serializeArray
();
var
form
=
new
FormData
();
$
.
each
(
form_data
,
function
(){
form
.
append
(
this
.
name
,
this
.
value
);
});
form
.
append
(
'goods_img'
,
$
(
'.goods_img'
)[
0
].
files
[
0
]);
$
.
each
(
$
(
'.goods_photo'
),
function
(){
form
.
append
(
'goods_photo[]'
,
this
.
files
[
0
]);
});
$
.
ajax
({
type
:
'POST'
,
url
:
"
<?=
site_url(
'Goods/insert'
)
?>
"
,
data
:
form
,
dataType
:
'json'
,
cache
:
false
,
contentType
:
false
,
processData
:
false
,
success
:
function
(res){
alert
(res.
message
);
if
(res.
code
==
0
){
return false
;
}
location
.
href
= res.
url
;
}
});
});