上一篇博客说了ajaxgetjsonp跨域方式,需要注意的一些事项下面说一下post方式传输数剧以及后端接受。
先直接上ajax代码:
$(document).ready(function() {
$('#submit1').click(function(){
var data = new FormData($("#form1")[0]); //$("form").serializeArray();
//formData = new FormData(data);
data.append("serect", 12324234);
console.log(data);
$.ajax({
type:"POST",
url:"http://test/fuck",
data: data,
crossDomain: true,
contentType: false,
processData: false,
dataType: 'json',
success:function(data) {
}
});
return false;
});一就是要在入口文件配置cros代码如下:
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')
->header('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, X-Requested-With, Origin')->send();
$kernel->terminate($request, $response);
\App\Http\Middleware\VerifyCsrfToken::class,
下边上服务端php代码
public function fuck(Request $request){
$data = $request->all();
return json_encode($data);
}
java服务端的我没接触过,以后再补上
以上就介绍了 ajax跨域post方式,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号