Ajax POST to Node.js through Nginx not getting correct response -


i'm trying send ajax post request node.js microservice through nginx. requuest follows:

$.post('http://localhost:80/api/signup', formdata, function( data, status) {     console.log(json.stringify(data));     console.log(json.stringify(status));         }).done(function(data, status) {             alert( "second success" );             console.log(json.stringify(data));             console.log(json.stringify(status));         })         .fail(function(data, status) {             console.log('error');             console.log(json.stringify(data));             console.log(json.stringify(status));         })         .always(function(data, status) {             console.log(json.stringify(data));             console.log(json.stringify(status));             console.log('fiished');         }); 

the request reaches microservice. response follows (which error function):

"data" always:

{"readystate":0,"status":0,"statustext":"error"} 

and "status" always:

error 

which not expected response @ success nor failure. how can fix this?

moreover, "formdata" parameters appear queries on url once submitted. how can stop that?

update*

i have tried adding event.preventdefault(); gives me following:

 xmlhttprequest cannot load http://localhost:3000/api/signup. no 'access-control-allow-origin' header present on requested resource. origin 'null' therefore not allowed access. {"readystate":0,"status":0,"statustext":"error"} 

i have tried:

$.ajax({           type: "post",           url: "http://localhost:3000/api/signup",           data: json.stringify(formdata),           success: function(datastring) {               console.log(json.stringify(datastring));         }, error: function(error) {             console.log(json.stringify(error));         }     }); 

but got same no 'access-control-allow-origin' header present on requested resource above.

update there valid , possibly more detailed answer on "no 'access-control-allow-origin' header present on requested resource". however, find answer accepted here more direct , clear.

are executing ajax request browser or localhost? if executing browser may cors issue. if want able execute ajax request browser should modify server configuration/code allow cross-origin http requests.

this looks similar issue. cors issue in jquery ajax post


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -