javascript - PHP echoing emptying string in $.ajax response -


I am trying to retrieve data from an AJAX call. I have tested with a string but it is returning empty, I just want to console the response to the string.

JS:

  makeRequest: function (sService, oData) {var request = $ .post ( '.. /../Utils/utils/php/userQuery. Php ', {' service ': sService,' oData ': oData},' json '); Request.done (function (oResult) {// This is to stop firing, but an empty string is printed console.log (JSON.stringify (oResult)); var fail = errorHandler.check (oResult); if (! Fail ) {It is firing off but empty string console.log (oResult);} else {console.log (unsuccessful);}}) is printing; Request.fail (function (oResult) {console.log ("There was an error retrieving service data");}); }  

PHP: class request {private $ sService; Function _ composition ($ sService) {$ _SESSION ['user_Id'] = 100000; $ This- & gt; $ S service = $ sService; Switch ($ this- & gt; $ sService) {Case 'Followers': Break; Case 'followee': break; Case 'Promoter': Break; Case 'Promotions': Break; Case 'Note': // It should be hit and revert back to "hit" json_encode ("hit"); break; Case 'Follow Up': Break; Cases 'Making Promotions': Break; Case 'Create Note': Break; Default: Echo "Error code: 4000"; break; }}} $ Request = new request ($ _ POST ['s service']);

If I $ Trying ParseJSON (oResult) , I get an error in parsing because it's empty where am I going?

Answer:

The updated code of the above work was a number of problems provided by the answer.

  1. I () to produce 2 _ did not add [before: _construct after: __construct]
  2. I do not $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

I hope it helps someone else. In

use

  1. Server dev-tools in your browser to check the reaction. Maybe the reaction is actually empty?
  2. You want to get JSON data, but you do not output json_encode
  3. PHP constructor 2 underscore: __ construct (not _construct )
  4. $ sService = $ _POST [ 'service']; should be $ this-> SService = $ _POST ['service'];
  5. When you new request ();

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -