jQuery AJAX POST to PHP issue -


I'm trying to evaluate the value of id , which should pass with POST Returning to jQuery

call {'id': '99'} for PHP, which is fine if id is not equal to 0. I wonder why ($ x == "0") is not being evaluated on true in my PHP function.

Any help would be greatly appreciated! Thanks in advance.

jQuery:

  $ (document) .ready (function () {$ .ajax ({url: '/more.php', type: 'post', Data: JSON.stringify ({"id": "0"}), success: function (data) {$ ("body"). Append (data);}})}}; If (isset ($ _ POST ['id'])) {$ con = mysqli_connect ("localhost", "user")  

PHP:

 , "Pass", "schema"); Getmore ($ _ post ['id']); Fashion getmore ($ x) {if ($ x == "0") {$ sqldata = mysqli_query ($ con, "Select from diretime», date_sub (curdate, interval 1 day) from IRcom;); } And ($ sqldata = mysqli_query ($ con, "select DATETIME from IRCLOG> date_sub (curdate), interval 1 day)"); } // Your business argument $ rows = array (); While ($ r = mysqli_fetch_array ($ sqldata)) {$ rows [] = $ r; } Echo json_encode ($ rows); }} Else {echo "{'id': '99'}";}  

I think this may be because PHP is changing $ _ POST ['id'] to the integer try the following:

  function getmore ($ X) {$ x = interval ($ x); If ($ x == 0) {  

Another reason may be that your AJAX data is being sent incorrectly. Try to use the data: Data: {id: "0"}

Accepting the setting plain object {/ code> or string argument in the code> AJAX call. From Docs:

This is converted to a query string, if there is no string already. It has been added to the URL for GET-requests. See the processData option to prevent this automatic processing. The object key / value must be added. If the value is an array, then sorting multiple values ​​with the same key based on the value of the traditional settings of jQuery (described below).


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -