Welcome Guest, Not a member yet? Register   Sign In
Undesired URL after running Javascript
#1

[eluser]cinewbie81[/eluser]
Hi all,

I have a image button with POST method = 'customer/action' - as shown following
Code:
<?php echo form_open('customer/action'); ?>
<input type="image" name="edit" onclick="ExecuteEdit()" src="<?php echo base_url();?>images/edit.gif" value="Edit">
<?php echo form_close(); ?>

Here's my ExecuteEdit() javascript
Code:
function ExecuteEdit()
{
   /* -- Start --
      Statement to get the Edit Key
   */ -- END --

   parent.location = mywebsiteurl + "customer/action" +"?d="+editKey+"&sid;="+Math.random();
}

My question is:
When i click on that image button, it return me the url www.mysite.com/customer/action. I want something like www.mysite.com/customer/action?d=7&sid=0.3104892969145657 .. Anyone ?
#2

[eluser]tonanbarbarian[/eluser]
you would be better off creating the link as something like the following
www.mysite.com/customer/action/d/7/sid/0.3104892969145657

then use something like the following in your controller
Code:
$params = $this->uri->uri_to_assoc(3);

this will produce an array of name value pairs like this

Code:
[array]
(
    'd'=>7,
    'sid'=>0.3104892969145657
)

I have not personally used this yet but this is what the user guide says
Look under the URI Class for more information

Basically CI does not like ?x=y&a=b in the url.
You can change the config to allow it in config.php file by setting the following
Code:
$config['enable_query_strings'] = true;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';

but then all of your urls would be
www.mysite.com/index.php?c=customer&m=action&d=7&sid=0.3104892969145657

personally I prefer the cleaner CI urls
#3

[eluser]cinewbie81[/eluser]
Hi tonanbarbarian,

I guess you misunderstood me.
The problem now is in my ExecuteEdit() javascript function, when i set
parent.location = mywebsiteurl + "customer/action" +"?d="+editKey+"&sid;="+Math.random();, it seems to me that it doesn't take effect on the url .. why is that so ??
#4

[eluser]coolfactor[/eluser]
Everything after the "?" is not part of the url.. they are url arguments. How are you testing this?
#5

[eluser]cinewbie81[/eluser]
Hi,

Ignore the ”?d="+editKey+"&sid;="+Math.random() part ..


Now, even though i set

parent.location = mywebsiteurl + “customer/another_action” , it will still return me back to
www.mywebsite.com/customer/action instead of www.mywebsite.com/customer/another_action ..

i doubt it has something to do with form_open('customer/action') as shown in code above .. i could be wrong though
#6

[eluser]coolfactor[/eluser]
What exactly does the mywebiteurl variable contain?
#7

[eluser]cinewbie81[/eluser]
mywebsiteurl variable is actually base_url() ..
when i alert it it will return me "www.mywebsite.com" ..
#8

[eluser]coolfactor[/eluser]
Probably a good idea to have it start with http://
#9

[eluser]cinewbie81[/eluser]
It's the same ...
see, even if i change parent.location.url to http://yahoo.com , it also go to www.mywebsite.com/customer/action
#10

[eluser]coolfactor[/eluser]
Not sure if it makes any difference, but I always use window(dot)location, not parent.location. But then again, I never build framed sites.

(I wasn't able to type it out normally in this forum post)




Theme © iAndrew 2016 - Forum software by © MyBB