Note that there are some explanatory texts on larger screens.

plurals
  1. POPost after ajax call not set isn't set (using jQuery)
    text
    copied!<p>I have this AJAX call:</p> <pre><code>$.ajax({ url: '../php/functions/area_id_to_table_name.php', type: 'POST', dataType: 'json', scriptCharset: "utf-8", data: { areaOfWorkId: userAreaOfWorkArray } }).always(nextStep); function nextStep(a, textStatus, b) { if (textStatus === 'success') { // success alert(a); } else { // failure alert('Failed: ' + b); } } </code></pre> <p>and this PHP code (the URL):</p> <pre><code>&lt;?php require_once 'connection.php'; $link = conenct('localhost', 'root', '', 'w_db'); mysql_query( "SET NAMES utf8" ); mysql_query( "SET CHARACTER SET utf8" ); mysql_set_charset('utf8', $link); Class AreaInfo{ public $areaName; public $areaId; public $areaTableName; } print_r($_POST['areaOfWorkId']); $areaOfWorkArray = $_POST['areaOfWorkId']; $areaInfoArray = Array(); foreach ($areaOfWorkArray as $key){ $key = mysql_real_escape_string($key); if ($key == 0) continue; $tmpObj = new AreaInfo(); $tmpObj-&gt;areaId = $key; $query = mysql_query("SELECT areaOfWork, tableName FROM area_of_work WHERE id = '$key'"); $query = mysql_fetch_assoc($query); $tmpObj-&gt;areaName = $query['areaOfWork']; $tmpObj-&gt;areaTableName = $query['tableName']; array_push($areaInfoArray, $tmpObj); } print_r($areaInfoArray); echo json_encode($areaInfoArray); ?&gt; </code></pre> <p>I am getting alert of this error:</p> <blockquote> <p>Failed: SyntaxError: JSON.parse: unexpected character </p> </blockquote> <p>On the Chrome developer tool it seems that all works fine. When I open the PHP page i see this lines:</p> <blockquote> <p>Notice: Undefined index: areaOfWorkId in C:\xampp\htdocs\job-skills\php\functions\area_id_to_table_name.php on line 15</p> <p>Notice: Undefined index: areaOfWorkId in C:\xampp\htdocs\job-skills\php\functions\area_id_to_table_name.php on line 16</p> <p>Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\job-skills\php\functions\area_id_to_table_name.php on line 19</p> </blockquote>
 

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