Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON data response from PHP server is empty
    primarykey
    data
    text
    <p>I'm having a hard time figuring this one out. Seems like no matter what I try, PHP always ends up returning an empty array. Here's the code of my main file(index.php):</p> <pre><code>&lt;script language="javascript" type="text/javascript"&gt; $(document).ready(function(){ $(".ajaxlink").click(function() { callServer(); return false; //Stop link from redirecting }); }); var test = { "testName": "testValue" } var testJSON = JSON.stringify(test); function updatePage(data) { document.getElementById("testDiv").innerHTML = data; } function callServer() { $.ajax({ type: "POST", url: "ajax/server.php", data: testJSON, success: function(data) { updatePage(data); }, //Upon error, output message containing a little info on what went wrong error: function (XMLHttpRequest, textStatus, errorThrown) { alert('An Ajax error occured\ntextStatus = ' + textStatus + '\nerrorThrown = ' + errorThrown + '\nstatus = ' + XMLHttpRequest.status); } }); } &lt;/script&gt; &lt;div id="testDiv"&gt;Something here&lt;/div&gt; &lt;a href="test1.htm" class="ajaxlink"&gt;Link!&lt;/a&gt; &lt;br&gt; </code></pre> <p>This basically runs the callServer() function when you click the "Link!". It then sends the test json data, that is { "testName": "testValue" } to server.php. Firebug reports that the json-data is indeed sent to the server.php.</p> <p>My server.php looks like this:</p> <pre><code>&lt;?php print_r($_POST); ?&gt; </code></pre> <p>This returns the following in the testDiv:</p> <pre><code>Array ( ) </code></pre> <p>The datatype in the .ajax function is not defined, so whatever output the server.php file spits out, it should be readable. All the necessary libraries(json, jquery) are included in my document as well. I'm running this on Apache 2.2 and PHP 5.3.1, but it shows the same on my webserver (which is a host for thousands of websites). The content-type used in the request-header is 'application/x-www-form-urlencoded; charset=UTF-8' so that should work correctly.</p> <p>Thanks for your time. Best regards soren</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload