如何使用JQuery post方法

参见英文答案 > How can I upload files asynchronously?32个
$.post('image.PHP',{
    image:form.image.value  
}


<form id="form" enctype="multipart/form-data">
<input type="file" id="image" name="image"/>

PHP的> isset($_ FILES [ ‘文件’])

如何使用$.post()在表单标记内发布$_FILES?
我还需要包含enctype吗?
或者我需要使用AJAX,我该怎么做?

解决方法

使用jQuery表单插件向AJAX提交带有文件的表单.
http://malsup.com/jquery/form/

在JS中

$('#form').ajaxSubmit({
 success: function(response) {
  console.log(response);
 } 
});

PHP

// after doing upload work etc

header('Content-type: text/json');
echo json_encode(['message' => 'Some message or param whatever']);
die();

完整的文档和示例:http://malsup.com/jquery/form/#ajaxSubmit

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...