Reputation: 917
I have problems with JSON on Chrome and Opera for several days, I managed to fix some errors but now I'm stuck and can't find a way out. I create some array in PHP, encode it in JSON and send it to javascript file where I process it further. In Firefox everything is ok, but in Chrome and Opera $.post()
function is never called. I assume it stop working when javascript needs to receive JSON data. Your help is so much needed.
This is my javascript function:
var updateGroup = function(id){
$("#unshareTable").html("");
passID = id;
$.post("getData.php", {'id' : id}, function(obj){
globalColor = obj.color;
$("#updateGroupTitle").val(obj.title);
$("#updateColorpickerHolder").css("background-color", obj.color);
$("#updateColorHex").html(obj.color);
var color2 = lighterColor(obj.color, .4);
$("#updateColorHex2").html(color2);
$("#updateGroupDescription").html(obj.description);
$("#unshareTable").append("<tr id='firstRowUnshare'><td>Username</td><td>Option</td></tr>");
$.post("getUnshareData.php", {'title' : obj.title}, function(obj1){
var length = obj1.length;
for(var i = 0; i < length; i++){
$("#unshareTable").append("<tr><td class='unshareUsername'>"+obj1[i].username+"</td><td><label class='unshareOneButton'>Unshare</label></td></tr>");
}
}, "json");
}, "json");
$(".updateGroupDiv").fadeIn(300);
}
and simple PHP script
<?php
$id = clean($_POST['id']);
$query = $mysqli->query("select * from groups where id_group = '$id'");
$data = $query->fetch_assoc();
echo json_encode($data);
?>
Also in Chrome I get these error:
Uncaught TypeError: Cannot call method 'getURL' of undefined
Uncaught TypeError: Cannot read property 'onRequest' of undefined
Upvotes: 1
Views: 8731
Reputation: 3512
In your PHP, add the following to the first line (after your opening tag)
header("Content-Type: text/javascript; charset=utf-8");
It specifies the response as JSON
Upvotes: 2