I am writing an AJAX function, but it looks like there is an error. I can't seem to find any. Please help! I have browsed these questions: this, this, and this but none of it is working. Here is my code:
function registerDevice(fp,uid)
{
$.ajax({
type: "POST",
async: true,
url: "backend.php",
data: {"fp": fp, "uid" : uid},
success: function(output) {
var json = eval('(' + output + ')');
var status = json['status'];
if(status == "success")
{
//redirect user.
setTimeout(function(){
//do what you need here
<?php
if(isset($_GET['goto']))
{
echo 'window.location.replace("'.$_GET["goto"].'");';
}
else
{
echo 'window.location.replace("index.php");';
}
?>
}, 2000);
}
else
{
$("#login-msg").text("Something went wrong. Please try again.");
$("#login-alert").fadeTo(4000, 500).slideUp(500, function(){
$("#login-alert").hide();
});
}
},
error: function(error) {
$("#login-msg").text("There was an unknown error.");
$("#login-alert").fadeTo(4000, 500).slideUp(500, function(){
$("#login-alert").hide();
});
}
});
}
and it is called like this:
$('body').on("click", "#mybtn", function (e) {
registerDevice(result,uid);
});
Here is the error I get in Google Chrome:
VM411:1 Uncaught SyntaxError: Unexpected token )
success @ login_alpha.php:344
j @ jquery.js:3148
fireWith @ jquery.js:3260
x @ jquery.js:9314
b @ jquery.js:9718
P.S: line 344 refers to this line:
var json = eval('(' + output + ')');
Edit 1: backend.php
<?php
$uid = $_POST['uid'];
$fp = $_POST['fp'];
//my code here.
$response_array['status'] = "success";
$response_array['type'] = "cookie";
?>