The previous blog talked about the ajaxgetjsonp cross-domain method. Some things that need to be paid attention to are discussed below. The post method transmits data and the backend accepts it.
First go directly to the ajax code:
$(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; });
The first is to configure the cros code in the entry file as follows:
$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);
AppHttpMiddlewareVerifyCsrfToken::class,
Below is the server-side php code
public function fuck(Request $request){
. I haven't touched it yet, I will make up for it later
The above introduces the ajax cross-domain post method, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.