Note that there are some explanatory texts on larger screens.

plurals
  1. POSending information via ajax partially working/failing
    primarykey
    data
    text
    <p>I am trying to send information about the user browser to a mysql database via ajax and this method that used to work perfectly on another site is now working partially, meaning that the data about the screen and browser width/ height, the color and pixel depth don't appear in my database and the information collected via php are sent/ saved.</p> <p>Here is what I have in my index.html file:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;&lt;html lang="en"&gt; &lt;head&gt; &lt;title&gt;Welcome&lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8" /&gt; &lt;script type="text/javascript"&gt; function ajax_post() { var hr = new XMLHttpRequest(); var url = "st.php"; var sw = screen.width; var sh = screen.height; var bw = document.documentElement.clientWidth; var bh = document.documentElement.clientHeight; var cd = screen.colorDepth; var pd = screen.pixelDepth; var vars = "sw="+sw+"&amp;sh="+sh+"&amp;bw="+bw+"&amp;bh="+bh+"&amp;cd="+cd+"&amp;pd="+pd; hr.open("POST", url, true); hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); hr.onreadystatechange = function() { if(hr.readyState == 4 &amp;&amp; hr.status == 200) { var return_data = hr.responseText; } } hr.send(vars); }; ajax_post(); &lt;/script&gt; &lt;link rel="stylesheet" type="text/css" href="style.css" /&gt; &lt;/head&gt; &lt;body&gt; My content here &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and here is the content of the st.php file used to collect information via php and to send/ seve it to the database:</p> <pre><code>&lt;?php $dnt = date(DATE_COOKIE); $ip = $_SERVER['REMOTE_ADDR']; $rh = gethostbyaddr($ip); $re = $_SERVER['HTTP_REFERER']; $ua = $_SERVER['HTTP_USER_AGENT']; $al = $_SERVER['HTTP_ACCEPT_LANGUAGE']; $sw = $_POST['sw']; $sh = $_POST['sh']; $bw = $_POST['bw']; $bh = $_POST['bh']; $cd = $_POST['cd']; $pd = $_POST['pd']; $db_host = ********; // the host $db_user = ********; // the user $db_password = ***********; // the password $connection = mysql_connect($db_host, $db_user, $db_password) or die(mysql_error()); mysql_select_db(*******) or die(mysql_error()); $query = "INSERT INTO *********(dnt, ip, rh, re, ua, al, sw, sh, bw, bh, cd, pd) VALUES ('".mysql_real_escape($dnt)."','".mysql_real_escape($ip)."','".mysql_real_escape($rh)."','".mysql_real_escape($re)."','".mysql_real_escape($ua)."','".mysql_real_escape($al)."','".mysql_real_escape($sw)."','".mysql_real_escape($sh)."','".mysql_real_escape($bw)."','".mysql_real_escape($bh)."','".mysql_real_escape($cd)."','".mysql_real_escape($pd)."')"; mysql_query($query) or die(mysql_error()); ?&gt; </code></pre> <p>I checked that I wasn't blocking any script (deactivated noscript), I tried it on Firefox and Chrome and Epiphany without any success: no data about the screen and browser width/ height, the color and pixel depth.</p> <p>I don't have any idea why this is not working as I used exactly the same code one week ago on a website on the same host and it worked perfectly.</p> <p>Thank you for your help.</p> <p>----- EDIT -----</p> <p>Thanks to @PiTheNumber I checked the Firebug Console and tracked the origin of the problem</p> <p>Problem solved</p> <p>Waiting 6 more hours to be able to answer my own question since I have less than 100 points of reputation and therefore cannot answer it right now.</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