表单序列化+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');

 

 也是跨域,表单提交

 

 

------------------------------------------------------成功案例----------------------------------------------------

 

 

 ------------------------------------------------------------------------------------------------------------------------------------------------------------

表单序列化提交:

 

 

 

 

 

 

 

 

 

posted @ 2019-06-12 23:11  搬砖小伙子  阅读(715)  评论(0编辑  收藏  举报