如何在wordpress ajax中使用FormData?我正在将文件和字符串附加到formdata。
var formdata = new FormData();
formdata.append(\'name\', \'This is Name\')
$.ajax({
url: \'admin-ajax.php\',
type: \'POST\',
data: {\'action\':\'plugin_save\', \'data\':formdata},
contentType:false,
processData:false,
success: success,
error: error
});
// php
sends 0 ?
最合适的回答,由SO网友:Milo 整理而成
操作应该是数据对象的一部分:
var formdata = new FormData();
formdata.append(\'name\', \'This is Name\');
formdata.append(\'action\', \'plugin_save\');
$.ajax({
url: \'admin-ajax.php\',
type: \'POST\',
data: formdata,
contentType:false,
processData:false,
success: success,
error: error
});