I'm getting Syntax Errors when calling a php file with ajax.
Uncaught SyntaxError: Unexpected token F
Uncaught SyntaxError: Unexpected token F
Uncaught SyntaxError: Unexpected token F
Uncaught SyntaxError: Unexpected token F
Uncaught SyntaxError: Unexpected token F
Uncaught SyntaxError: Unexpected token F
The change_produkt
function is called with an onclick event in a checkbox field.
The output of this function is as following:
Now, I call the second function fill_optionen
and pass the arrays to that function. It's doing ajax calls for each object. (6 times in this case)
Javascript:
function fill_optionen(optionen) {
console.log("fill_optionen called.."); // Debug
var text = "";
$j.each(JSON.parse(optionen), function (index, value) {
jQuery.ajax({
url: 'include/mutation_helper.php',
data: {func: "render_opt", option: value},
type: 'post',
success: function(output) {
console.log(JSON.parse(output)); // Debug
}
});
});
}
function change_produkt() {
console.log("change_produkt called.."); // Debug
var id_produkt = $j("#produkt").val();
console.log("DEBUG -- id_produkt:"+id_produkt);
jQuery.ajax({
url: 'include/mutation_helper.php',
data: {func: "get_opts", produkt: id_produkt},
type: 'post',
success: function(output) {
console.log(JSON.parse(output)); // Debug
fill_optionen(output);
}
});
}
PHP:
function render_opt() {
if(!isset($_POST['option'])) {
echo json_encode("error");
exit;
}
$opt = $_POST['option'];
$render = render($opt, $_SESSION['mutation']);
echo json_encode("hello");
}
As soon as I remove the line which calls the render
function, it works. But why is there an error? I'm not even printing out that $render
variable.
(The render
function only returns html code in a string.)