尝试使用FormData,formdata对象发送ajax post请求,如果可以,但ajax不会发送它。 FormData部分:
var request_data = new FormData();
// var request_data = new FormData($("#user_form")[0]); tried this also//
request_data.append('table', 'students');
request_data.append('name', $("#name").val());
request_data.append('email', $("#email").val());
request_data.append('phone', $("#phone").val());
request_data.append('check', $("#check").val());
request_data.append('image', image);
ajaxCall(request_data);
ajax请求部分:
$.ajax({
type: "POST",
url: "../src/api.php/InsertTo/",
dataType: 'multipart/form-data',
cache: false,
async: false,
contentType: false,
proccessData: false,
data: request_data,
success: function() {
alert("data");
$('form').hide();
$('#post_save').append("Object Successfully Inserted!");
//call get API //
},
error: function(jqXHR, textStatus, errorThrown) {
alert(JSON.stringify(jqXHR));
}