php - $_POST is empty even though I can see the $_POST data in firebug post, html, and response tabs -


so i'm grabbing state of jquery date picker , dropdown select menu , trying send 2 variables php file using ajax.

var_dump($_post); 

results in on webpage:

    array(0) {    } 

but, when @ net panel in firebug, can see post , urls , shows post, response, , html showing variables sent php file, when dumping, shows nothing on page.

i've been looking through other similar issues on has led me changing php.ini file increase post size , updating ajax call use json objects , parse through on php side.

currently i'm trying passing string work, , code looks this:

ajax:

  $("#submit_button").click(function() {     // date if selected     var selected_date = $("#datepicker").datepicker("getdate");     // show id if selected     var selected_dj = $("#show-list").val();     // put variables json object     var json = {demo : 'this simple json object'};     // convert json     var post_data = json.stringify(json);     // put in variable posting     var post_array = {json : post_data};      $.ajax({       type: "post",       url: template_dir + "/get-show-logs.php",       data: post_array,       success: function(){           alert("query submitted");       },       error: function(xhr, ajaxoptions, thrownerror){         alert(xhr.status);         alert(thrownerror);       }     });        // clear div make room new query     $("#archived-posts-container").empty();     // load data     $("#archived-posts-container").load(template_dir + "/get-show-logs.php #get_logs");    }); 

now php that's running .load() call, , i'm trying access $_post variables:

get-show-logs.php:

<div id="get_logs">      <?php       if(isset($_post["json"])){         $json = stripslashes($_post["json"]);         $output = json_decode($json);          echo "im here";         var_dump($output);          // can access php object         // $output[0]->variable-name     }      var_dump(getrealpost());       function getrealpost() {         $pairs = explode("&", file_get_contents("php://input"));         $vars = array();         foreach ($pairs $pair) {             $nv = explode("=", $pair);             $name = urldecode($nv[0]);             $value = urldecode($nv[1]);             $vars[$name] = $value;         }         return $vars;     }      ?>  </div> 

you can see i'm trying accessing $_post variable, , isset check isn't passing, (the page isn't echoing "im here"), , i'm trying parsing through input myself, , empty.

the output on page looks this:

array(1){[""]=>string(0)""}

but, once again, firebug net panel shows following under response tab:

    <div id="get_logs">      im hereobject(stdclass)#1 (1) {     ["demo"]=>      string(33) "this simple json object"    }    array(1) {      ["json"]=>      string(44) "{"demo":"this simple json object"}"    }      </div> 

i'm not sure causing issue, firebug can see it, php file sees empty array.

now i'm new @ using ajax , $_post , such, if read you're not 100% sure about, don't assume know it! speak up! haha. also, i'm doing mamp on localhost, i'm not sure if leads issues.

thanks in advance!

you aren't using response in ajax call currently. see example output returned response console.

$.ajax({       type: "post",       url: template_dir + "/get-show-logs.php",       data: post_array,       success: function(response){           console.log(response);       },       error: function(xhr, ajaxoptions, thrownerror){         alert(xhr.status);         alert(thrownerror);       }     }); 

success
type: function( data, string textstatus, jqxhr jqxhr ) function called if request succeeds. function gets passed 3 arguments: data returned server, formatted according datatype parameter or datafilter callback function, if specified; string describing status; , jqxhr (in jquery 1.4.x, xmlhttprequest) object.

-http://api.jquery.com/jquery.ajax/

also might page read more jquery , ajax, https://learn.jquery.com/ajax/jquery-ajax-methods/.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -