表单序列化+ajax跨域提交
php后台代码:
use cmf\controller\HomeBaseController;
use think\Db;
header('Access-Control-Allow-Origin:*');
// 响应类型
header('Access-Control-Allow-Methods:*');
// 响应头设置
header('Access-Control-Allow-Headers:x-requested-with,content-type');
class IndexController extends HomeBaseController
{
public function get()
{
//$data = input('get.');
$data = [
'email'=>input('get.email'),
'name'=>input('get.name'),
'phone'=>input('get.phone'),
];
$res = db('jsonp')->insert($data);
if($res){
return json(['code'=>200, 'msg'=>'成功']);
}
}
}
jsonp跨域请求响应头:
header('Access-Control-Allow-Origin:*');
// 响应类型
header('Access-Control-Allow-Methods:*');
// 响应头设置
header('Access-Control-Allow-Headers:x-requested-with,content-type');
也是跨域,表单提交
------------------------------------------------------成功案例----------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------
表单序列化提交: