jquery - Why is the server not giving me any responses? -


so have server supposed return json token authentication. isn't returning (i have printing messages console), not error message. mostly, has sent error message once or twice. i've tried fleshing out success complete , error functions. know form elements being picked because print console. i've had people confirm server working ajax requests, won't. not posting servers url obvious reasons.

$(function()   {      $("#login").click(function()     {      var username = $("#username").val();      var password = $("#password").val();       login(username, password);      });         function login(username, password)        {        $.ajax        ({          url: "/",          type: "post",          datatype: 'json',          contenttype: 'application/json',          data: '{"username": "' + username + '", "password" : "' + password + '"}',          success: function(data, text, xhr)          {            console.log(xhr.status);             console.log(data);             console.log(text);           },          error: function(xhr, status, error)          {            console.log("error" + xhr + status + error);          },           complete: function(xhr, text)           {           console.log(xhr.status, text);           }         });         }    }); 

in chrome, gives me no errors. in firefox:

post file/ http/1.1 200 ok error has occurederror jquery.min.js line 2 > eval:58:14 0 error jquery-latest.min.js line 2 > eval:62:13 complete jquery-latest.min.js line 2 > eval:63:13 options xhr addressofserver/  xhr object object { readystate: 0, getresponseheader:  .ajax/v.getresponseheader(), getallresponseheaders:  .ajax/v.getallresponseheaders(),  

setrequestheader: .ajax/v.setrequestheader(), overridemimetype: .ajax/v.overridemimetype(), statuscode: .ajax/v.statuscode(), abort: .ajax/v.abort(), state: .deferred/d.state(), always: .deferred/d.always(), then: .deferred/d.then(), 11 more… }

note "complete" , "error has occured" strings wrote in code. both pointing @ jquery. know link jquery working because grabbing user input.

also under post, says content type text/html although set json, otherwise seems okay:

vary:   accept-encoding server: apache/2.4.10 (ubuntu) last-modified:  fri, 22 apr 2016 20:10:32 gmt keep-alive: timeout=5, max=100 etag:   "c6c-531186b4ac855-gzip" date:   fri, 22 apr 2016 20:18:41 gmt content-type:   text/html content-length: 1078 content-encoding:   gzip connection: keep-alive host:   localhost connection: keep-alive accept-language:    en-us,en;q=0.5 accept-encoding:    gzip, deflate accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 

under options says

connection: keep-alive cache-control:  no-cache access-control-request-method:  post access-control-request-headers: content-type accept-language:    en-us,en;q=0.5 accept-encoding:    gzip, deflate accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 

it's printed under xhr object when high light it:

enter image description here

update 1:

one of buttons refreshing page before request sent. getting different error:

cross-origin request blocked: same origin policy disallows reading remote resource @ */link*. (reason: cors header 'access-control-allow-origin' missing). 

what trying adding $.ajax :

        crossdomain: true,        xhrfields: { withcredentials: true }, 

i still getting same error though.

things can identify problem source :

  • sending normal post request <form> , <input> , check response of server
  • opening browser dev tools , see if u weird
  • debug state of actual prob

also try change $.ajax $.post see method docs here : https://api.jquery.com/jquery.post/


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -