I am working in PHP Codeigniter. My page's current URL is => http://localhost.hbs.com/hbs/merchant/login
On an event i want to redirect my page to => http://localhost.hbs.com/hbs/category
I am trying following code,
window.location = '<?php echo json_encode(base_url("category"));?>';
also tried
=>window.location.href , top.location
But it redirects me to,
http://localhost.hbs.com/hbs/merchant/"http://localhost.hbs.com/hbs/category"
I've also tried for debugging this code, window.location = "google.com" but it redirects me to => http://localhost.hbs.com/hbs/merchant/google.com
You are using ` characters in your string and I'm not sure why?
Change your redirect to this:
window.location = '<?= json_encode(base_url("category)) ?>';
In explanation, using
<?= value ?>
is the shorthand form of
<? echo value ?>
You've got extra quotes around the url. Try this...
window.location = '<?php echo json_encode(base_url("category"));?>';
Solved : json_encode() puts quotes around string. used following code and everything becomes ok.
var url = '<?php echo json_encode(base_url("category"));?>';
url = url.replace(/"/g, "");//to replace quotes with ""
window.location = url;
use this:-
window.location.href = '<?php echo json_encode(base_url("category"));?>';
-- EDIT -- You could use PHP to detect if they or the event is true or equal to something and if it is do
header("Location: /hbs/category");
That might also be a non-js solution if you could use it in this case..
For example:
if (foo()===true){
header("Location: /hbs/category");
}
window.location = "http://localhost.hbs.com/hbs/category"
Also
window.location = "google.com"
makes it think it's pointing to something in the folder (ex. hbs/index.html, not a new site.) You'd want
window.location = http://google.com