Hello ppl.
Im getting status code 0 on any HTTP error. On chrome network tab says 409, 422 but the object come whit the wrong status.
Tks !
Code:
this.$http.post('http://localhost/sigmapi/public/api/' + this.apiName, {nome: this.novoNome})
.then(function (response) {
this.dados.push(response.data['data'])
this.novoNome = ""
swal({
title: "Criado",
text: "Voc锚 criou a configura莽茫o " + response.data['data'].nome + "",
html: true,
type: "success"});
}, function (response) {
if(response.status == 409){
var errorMsg = "Desculpe, mas a configura莽茫o " + this.novoNome + " j谩 existe.";
}
if(response.status == 422){
var errorMsg = "O nome da nova configura莽茫o n茫o pode ser vazio."
}
swal("Erro", errorMsg, "error");
});
I understand my problem. It was CORS not enable for http 400 family.
Tks all
@odranoelBR excuse me锛宑ould you tell me how you fix this problem锛焧hank you!
Hi @rongself !
This problem comes from the API / WebService you tryng to request.
Take a read in https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
You must enable cross realm on your API.

You building the API or using third ?
@odranoelBR
Thank you! this is a lot of help for me , I am building the API use Laravel,this is the code i set the response header:
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
$response = $next($request);
$httpOrigin = $request->header('Origin');
if ($httpOrigin && in_array($httpOrigin, explode(',', env('CORS_DOMAINS')))) {
$response->header('Access-Control-Allow-Origin', $httpOrigin);
$response->header('Access-Control-Allow-Credentials', 'true');
$response->header('Access-Control-Expose-Headers', 'Authorization');//鍏佽鏈嶅姟鍣ㄦ帴鏀舵寚瀹氱殑瀹㈡埛绔彂閫佽繃鏉ョ殑鑷畾涔塰eader
if($request->getMethod() === Request::METHOD_OPTIONS){
$response->header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE');
$response->header('Access-Control-Allow-Headers', 'Authorization');//鍏佽娴忚鍣ㄥ彂閫佹寚瀹氱殑鑷畾涔塰eader
}
}
return $response;
}
so now the thing i need to to is set Public and Allow these response headers right?
@odranoelBR
I understand my problem,i stop the laravel framework when login failed:
abort(Response::HTTP_UNAUTHORIZED,$e->getMessage());
i think this will break the response,so i change it to :
return Response::create($e->getMessage(),Response::HTTP_UNAUTHORIZED);
now it work , thanks you and have a nice day
@rongself excuse me, i have some problem,I am front web dev , and back end framework is laravel. In some
phone(wechat 6.5.6,andorid 6.0, honor 7) will arise status that is 0. And Exclusion of cross-domain problem.
can you help me?
Most helpful comment
I understand my problem. It was CORS not enable for http 400 family.
Tks all