Note that there are some explanatory texts on larger screens.

plurals
  1. PO.ajax() post to callback file does not recognize php define constant
    primarykey
    data
    text
    <p>When using the code below I am having trouble setting the right location. Somehow in the callback file the php constant is not recognised, thus the rest of the code is not functioning.</p> <p>snippet from html:</p> <pre><code>&lt;a href="#" class="selectLocation" id="ABC"&gt; </code></pre> <p>snippet from .js</p> <pre><code>var locationID; $(".selectLocation").click(function(){ locationID = this.id; setLocation(); }); function setLocation() { $.ajax({ data: {location: locationID}, success: function (data) { // do something }; }); }; // DEFAULT AJAX SETUP $(function () { $.ajaxSetup({ type: "POST", url: "dir/callback.php", dataType: "json", cache: "false", error: function (jqXHR, exception) { if (jqXHR.status === 0) { console.log('No connecting.\n Verify Network.'); } else if (jqXHR.status == 400) { console.log('Bad Request. [400]'); } else if (jqXHR.status == 404) { console.log('Requested page not found. [404]'); } else if (jqXHR.status == 500) { console.log('Internal Server Error [500].'); } else if (exception === 'parsererror') { console.log(jqXHR.responseText); console.log('Requested JSON parse failed.'); } else if (exception === 'timeout') { console.log('Time out error.'); } else if (exception === 'abort') { console.log('Ajax request aborted.'); } else { console.log('Uncaught Error: ' + jqXHR.responseText); }; } }); </code></pre> <p>snippet from callback.php:</p> <pre><code> &lt;?php header("content-type:application/json"); session_start(); require_once ('config.php'); ... $connect-&gt;setLocation($_POST['location']); </code></pre> <p>the $_POST['location']; will send ABC to the rest of my code instead of the right value defined below.</p> <p>snippet from config.php:</p> <pre><code>define('ABC', 'some location'); </code></pre> <p>While if I do:</p> <pre><code>echo (ABC); </code></pre> <p>in the callback file, I <strong>will</strong> get the correct location value.</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.
 

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