Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP json_decode not supported, any alternatives?
    text
    copied!<p>as the title specifies, my hosting provider does not have support for json_decode, so I need to find a way to adapt my code to achieve the same effect, but without using JSON, here is my code,</p> <p>jQuery:</p> <pre><code> var allLocations = []; $(".locations").each( function(i, location) { // for each location block location = $(location); var loc = { 'province' : $("select[data-loc*='province']", location).val(), 'town' : $("select[data-loc*='town']", location).val() }; allLocations.push( loc ); }); //POST the locations information $.ajax({ type: 'POST', url: 'locations.php', dataType: 'json', data: { locations: JSON.stringify(allLocations), uid: uid }, success: function(data){ //alert(data) } }); </code></pre> <p>PHP:</p> <pre><code>$json = $_POST['locations']; $uid = $_POST['uid']; // $json is a string $json_array = json_decode($json, true); mysql_connect('localhost','user','pass') or die(mysql_error()); mysql_select_db('eskom_products') or die(mysql_error()); //insert the locations into the database while($json_array as $key){ $query = mysql_query("INSERT INTO suppliersLocations (supplier_id, province, town) VALUES('".$uid."', '".$key['province']."', '".$key['town']."' ) ") or die(mysql_error()); } echo $text; </code></pre> <p>So as you can see, I am getting the province and town values of each location and creating a JSON object with it, which I then send off via <code>$.ajax</code> to a PHP file, but now since <code>json_decode</code> doesn't work, I need to try and find another way of fixing the problem, I was thinking of trying to pass an associative array to the php file, but I wanted to see what your guy's input would be, and if there might be a better way of achieving the desired result.</p> <p>Thanx in advance!</p>
 

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