javascript - jQuery AJAX: unexpected end of input -


I am trying to check the value of the input using AXX. Every time the user is sent to a major AJAX and then the server is sent on the basis of the result I am adding valid or invalid class in the input.

.js:

  $ ("input [name = username]"). Key (function (event) {processAJAXCheck (this, "user name");}); $ ("Input [name = username]"). Change (function (event) {processAJAXCheck (this, "user name");}); Function processexcheck (element, to cheek) {contentOfInput = $ (element) .val (); $ .jax ({url: "ajax.php", type: "post", data: {content: contentOfInput, toCheck: toCheck}, success: AFJAXResponse}); } After the function, AJXSpace (data) {result = $ .SESSON (data); If (result ['toCheck'] = undefined) {inputSelector = 'input [name =' + result '[' check '] +'] '; If (result ['result'] == true) {$ (input selector) .removeClass ('invalid'); $ (InputSelector) .addClass ('valid'); FormValid = true; } And {$ (Input Chooser) .removeClass ('Valid'); $ (InputSelector) .addClass ('invalid'); FormValid = Incorrect; }} Result = null; Php code:  
  if (isset ($ _ POST ['toCheck']) and isset ($ _ POST ['content' ]) & Amp; $ _POST ['toCheck']! = "" And $ _POST ['content']! = "") {Require_once 'classes / AAA.php'; Need_once 'classes / database.php'; Need_once 'etc / settings.php'; $ Db = new database ($ globals ['db_source'], $ globals ['db_name'], $ globals ['db_user'], $ globals ['db_pass']); $ Aaa = new AAA ($ db); Switch ($ _ POST ['toCheck']) {case 'email': $ output ['result'] = $ aaa-> Useful email ($ _ POST ['content']); $ Output ['toCheck'] = 'email'; break; Case 'Username': $ Output ['Result'] = $ aaa- & gt; Use Usable Username ($ _ POST ['Content']); $ Output ['toCheck'] = 'username'; break; Default: $ output ['result'] = 'error'; break; } Echo json_encode ($ output); }  

The strange thing is that whenever I press any character key, everything works without problems but when I press "tab" to switch to another tab (Which uses the same function, but does not return any errors - even when I press tab there!) I get the following error:

  Uncaught syntax error: the unexpected input End b.extend.parseJSon jquery-1.9.1.min.js: 3AJAX liability after registration.php? School_id = 1 & amp; Department_id = 1: 18 9b. Callback Jquery-1.9.1.min.js: 3b. Callbacks. Screwfire Jquery-1.9.1.min.js: 3K jquery-1.9.1.min.js: 5 b.ajaxTransport.send.r  

For your responses in advance Thank you. However, if you do not want to call your AJAX function, press key is pressed; You are not checking for it, and keep also captures your tab click event.

You should change:

  $ ("input [name = user name]"). Key (task (event) {processAJAXCheck (this, "user name");});  

To do something like this:

  $ ("input [name = user name]"). Key (action) {if (event.keyCode! == 9) {// I think it's 9 ... process checking (this, "username");}});  

You can also add - 13 - for example.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -