I'm redirecting to pages based on the links clicked prior to login form submission. Form submitted via ajax, I noticed that only in live server, response passed from php script via ajax is not received. success: function(data) {//nothing works here}
.Thus the page is not redirected.In the php page, there's script to login the user. Surprisingly, after refreshing the page, user is logged in. AFter the user logged in, the redirection works perfectly.
I wonder why data is not passed from php via ajax and why redirection doesn't work?
My ajax..
$("#login").on("click",function()
{
// alert(this_link);
$("#login_form").submit(function(){
var data = {
"action": "test"
};
data = $(this).serialize() + "&" + $.param(data);
$.ajax({
type: "POST",
dataType: "json",
url: "login2.php?id='"+this_link+"'", //Relative or absolute path to response.php file
data: data,
success: function(data) {
$(".the-return").html("<br />JSON: " + data );
// alert("Form submitted successfully.
Returned json: " + data["json"]);
//alert(data);
//alert(data["json"]);
//console.log(data);
if(data=="'del_create'-1")
{
//window.location='create_post.php';
$(location).attr('href', 'https://sample.com/create_post.php');
}
else if(data=="'del_avail'-1")
{
//window.location='update_post.php';
$(location).attr('href', 'https://sample.com/update_post.php');
}
else
{
window.location='<?php echo $root;?>login/login.php';
}
}
});
data returned by php script
$id3=$id."-".$id2;
echo json_encode($id3);//returns 'del_avail'-1 or 'del_create'-1 if logged in and -0 if not logged in
Within the single quotes echo
does not work. Perhaps the following will work.
window.location="<?php echo $root;?>login/login.php";
or
window.location.href="<?php echo $root;?>login/login.php";