javascript - jQuery xhr.status returns 0 when sending request to localhost -


update - 2016-01-30

as advised in comments have:

  1. installed xampp
  2. put page on apache , ran server
  3. made sure page , scripts executing (simple alert test)
  4. set xhrfields: withcredentials false make cors request advised in answer , taught here

i still cannot pass request. console log:

xmlhttprequest cannot load http://localhost:8080/rimmanew/rest/appointments.  no 'access-control-allow-origin' header present on requested resource.  origin 'http://localhost' therefore not allowed access. response had http status code 400 

here how looks on 'user end' if of help: enter image description here

------------------initial ticket-----------------------------

i have java rest application runs locally , accepts far 1 method , returns json string: successful id call

another method post, supposed convert, validate , save information sent form , return 200 answer. if goes wrong during conversion, validation or persistence - exception thrown (e.g. badrequest or 500).

this rest method (i omitted brevity validating, build methods converter , converter provider classes):

@post @produces("application/json") @consumes("application/x-www-form-urlencoded") public response bookappointment(@formparam("date") date appdate,         @formparam("time") time apptime, @formparam("type") string apptype,         @formparam("clientname") string clientname, @formparam("email") string clientemail,         @defaultvalue("") @formparam("message") string clientmsg) {     //externalize validation of fields concentrate on "positive"     //scenario     validator(appdate, apptime, apptype, clientname, clientemail);     appointment appointment = build(appdate, apptime, apptype,clientname,                  clientemail, clientmsg);     try {         repository.add(appointment);         return response.ok(appointment).build();     } catch (exception e) {         throw new internalservererrorexception("something happened in application "                 + "and apointment not saved. please contact "                 + "to inform of issue.");     } } 

the client not within application (i thought may useful) - simple html file on computer has jquery script:

<script type='text/javascript'>     $(document).ready(function(){          $('form#appointmentform').submit(function(ev){              ev.preventdefault();             $.ajax({                 url: 'localhost:8080/rimmanew/rest/appointments',                 type: 'post',                 datatype: 'json',                 data: $('form#appointmentform').serialize(),                 contenttype: 'application/x-www-form-urlencoded',                 beforesend: function() {                                             $('#ajaxresponse').html("<img src='245.gif' />");                                         },                 success: function(data) {                     $('#ajaxresponse').html("<span style='color:white; background-color: green;' class='glyphicon glyphicon-ok'></span><p>"+json.stringify(data)+"</p>")                     .fadein("slow");                 },                 error:  function(xhr, ajaxoptions, thrownerror){                     $('#ajaxresponse').html("<span style='color:white; background-color: red;' class='glyphicon glyphicon-exclamation-sign'></span><p>status: ").append(xhr.status)                     .append("</p>").fadein("slow");                 }             });                        });                 }); </script> 

i want submit form in order access params @formparam annotated attributes. on every request send not receive of thrown errors , status 0. see erring or missing?

enter image description here

a status code of 0 means request didn't happen. in order have status code valid http interaction has happen, if none did there no status code.

the main reasons why happen are:

  1. the dns not resolved
  2. a connection host/port not established
  3. cors issues, html not being served same host/port server. in case need write cors policy allow specific domains make ajax request server.
  4. the html local file, special case of cors problem browser don't allow connections without host.

all of them should show error on javascript console ( weirdest cors shows failed options request )


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -