as indicated in the header, my hosting provider does not have json_decode support, so I need to find a way to adapt my code to achieve the same effect, but without using JSON, here is my code,
JQuery
var allLocations = [];
$(".locations").each( function(i, location) {
location = $(location);
var loc = {
'province' : $("select[data-loc*='province']", location).val(),
'town' : $("select[data-loc*='town']", location).val()
};
allLocations.push( loc );
});
$.ajax({
type: 'POST',
url: 'locations.php',
dataType: 'json',
data: { locations: JSON.stringify(allLocations), uid: uid },
success: function(data){
}
});
PHP:
$json = $_POST['locations'];
$uid = $_POST['uid'];
$json_array = json_decode($json, true);
mysql_connect('localhost','user','pass') or die(mysql_error());
mysql_select_db('eskom_products') or die(mysql_error());
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;
So, as you can see, I get the values for the provinces and cities of each location and create a JSON object with it, which I then send through $.ajaxto the PHP file, but now since it’s json_decodenot working, I need to try to find another way to solve the problem, I I was thinking of trying to pass an associative array to a php file, but I wanted to see what would happen to your boyfriend, and if there could be a better way to achieve the desired result.
Thanx in advance!