Tag: Timeout JSON object character bad ack 16px array. Text throw
1*****************************************************************2#fetch Request using isomorphic-fetch send FETCH request3 4Import fetch from ' Isomorphic-fetch ';//window Native method in ES65 6 Fetch (url,{7Method: "POST",8Headers: {"Content-type": "Text/plain"},9Body: "Firstname=nikhil&favcolor=blue&password=easytoguess"Ten}). Then (function(response) { One if(Response.Status >= 400) {//determine if the request was successful A Throw NewError ("Bad response from server!"); - } - //response.headers.get (' Content-type ') the //response.headers.get (' Date ') - //Response.Status - //Response.statustext - //Response.type + //Response.url - + returnResponse.json ();//to turn a promise object into a JSON object A //. Text (): return string at //. JSON (): Returns a JSON object - //. FormData (): Returns a FormData object - //. BLOB (): Returns a Blob object - //. ArrayBuffer (): Returns a binary array -}). Then (function(JSON) { -Console.log (JSON);//Execute your code in}).Catch(function(ex) { -Console.log (' request failed ', ex);//Exception Handling to }); +***************************************************************** - the***************************************************************** *#JSONP Request using fetch-Jsonp sending JSONP requests $ Panax NotoginsengImport Fetchjsonp from ' Fetch-jsonp '; - the Fetchjsonp (url,{ +JSONP: ' Callback ',//Do not set, default to become callback AJsonpcallback: ' Mycallback ',//Not set, random name generated by default thetimeout:3000,//Not set, default +Data:{a:1},//parameter finally generates a request for Url?a=1&callback=mycallback -}). Then (function(response) { $ returnResponse.json ();//accept the result as a promise object and turn it into a JSON object $}). Then (function(JSON) { -Console.log (JSON);//Execute the code you need -}).Catch(function(ex) { theConsole.log (' parsing failed ', ex);//Exception Handling - })Wuyi the!!! The data returned by JSONP cannot be pure json, but rather "function name (JSON)"The JS code -*****************************************************************
A new generation of Ajax Api--fetch based on promise object