Jump to content

Recommended Posts

Hey guys im having trouble making a header go off on a php script using ajax

wondering if anyone knows what I need to do to make this happend. I put to gether a real simple example

 

 

$(function(){  

$("select#name_list").change(function(){
	$.ajax({            

url: "/System_Lords/functions/function_common_buttons.php?functions=change_planet_ajax",            

		type: 'POST',            

		dataType: 'json',            

		data: { 

			name_list: $('#name_list').val()
	                         }
	});            
}); 
});

 

The function on the php script

function change_planet_ajax() { 

header("Location: /system_lords/dominion.php");exit();

}

Link to comment
https://forums.phpfreaks.com/topic/261087-making-a-header-fire-using-ajax/
Share on other sites

oh there is more code that goes with it. I just took it out.

 

changes a session then refreshes page. also validates something from data base

 

i have planets in a drop down box, as you change planets, it sets a default planet by updating a session

 

I can redirect using java script but IE8 has a bug with window.open it seems.

 

another idea i came up with is not using ajax at all. and just make a button hidden and fire the button.

 

This code is for making a buttonless drop down box

Okay... Still not sure what that redirect is supposed to do...

 

Are you trying to use it to redirect the original page? Can't do it that way. You'd have to send data that says "you need to redirect and here is where you need to go". Like maybe

echo json_encode(array("action" => "redirect", "location" => "/system_lords/dominion.php"));

success: function(data) {
    if (data && data.action == "redirect") {
        document.location = data.location;
    } else {
        // ???
    }
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.