形成查询字符串操作。 [英] Form querystring manipulation.

查看:110
本文介绍了形成查询字符串操作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在尝试创建一个简单的导航脚本。它允许您选择一个区域。选择区域后,将打开另一个列表,您可以选择该区域内的城市。一切正常,您可以自由更改城市并正确更新网址。但是如果您选择了一个城市并且想要重新选择该区域,那么城市ID将保留在会弄乱我的页面的网址中。


一些示例:

http://192.168.2.16/Seznam.php?IdR=1

http://192.168.2.16/Seznam.php?IdR=1&IdM=101

这两个是正确的网址,区域1和区域1的城市1.


如果你现在更改区域,你将得到这个。

http: //192.168.2.16/Seznam.php?IdR=4&IdM=101

这意味着区域1中的区域4和城市1.它应该将IdM(城市ID)设置为0或完全删除它。


有什么想法吗?


这是'我正在使用的代码。

Hi all,

I''m trying to create a simple navigation script. It allows you to select a region. Once region is selected another list opens up and you can select a city within that region. It all works fine, you can change cities freely and url updates correctly. BUT if you have a city selected and want to re-select the region, the city id stays in the url which messes up my page.

Some examples:
http://192.168.2.16/Seznam.php?IdR=1
http://192.168.2.16/Seznam.php?IdR=1&IdM=101
These two are correct urls, region 1 and city 1 in region 1.

If you now change the region you will get this.
http://192.168.2.16/Seznam.php?IdR=4&IdM=101
Which means region 4 and city 1 in region 1. It should set IdM (city id) to 0 or remove it completely.

Any ideas?

Here''s the code I''m using.

展开 | 选择 | Wrap | 行号

推荐答案

在您从第一个选择提交表单之前,只需重置第二个选择的值。


you可以通过使用AJAX进一步改进你的代码,这样你就不需要每次都重新加载页面。
before you submit the form from the first select, simply reset the value of the second select.

you could improve your code further by using AJAX, so that you don?t need to reload the page each time.


如果我添加一个名为IdM的隐藏输入,那么我得到这个:IdR = 1& IdM = 0& IdM =之前的任何内容。


我想我不明白你的意思。


关于ajax,我需要每次都刷新页面,因为这样所有链接都会获得新的路径。类似于webstore页面上的类别/子类别。
If I add a hidden input with name IdM then I get this: IdR=1&IdM=0&IdM=whatever it was before.

I think I don''t understand exactly what you mean.

About ajax, I need to refresh page each time because that way all links get new paths. Sort of like categories / subcategories on a webstore page.


@AnonG


a隐藏字段完全没用。
@AnonG


好​​吧,我有点明白吗?


ok,首先你要了解你的表格是如何工作的。你有2个表单字段(2x< select>(我将它称为S1和S2))

如果你调用form.submit()(在S1或S2中)浏览器检查每个表单字段并为每个表单字段创建一个名称 - 值对,并将其转换为URL(在您的情况下)。


现在的想法是,当你从S1调用submit()时,在实际调用之前,你需要重置S2的当前名称 - 值对(即只有值,因为名称没有改变)


表示为伪代码:
@AnonG
a hidden field is completely useless.

@AnonG
well, I kind of understand that?

ok, first you need to understand, how your form works. you have 2 form fields (2x <select> (I?ll refer to it as S1 and S2))
if you call form.submit() (either in S1 or S2) the browser checks every form field and makes a name-value pair for each and transforms that into an URL (in your case).

now the idea is that when you call submit() from S1, before you actually call it, you need to reset the current name-value pair of S2 (i.e. only the value, because the name is not changed)

expressed as pseudo code:
< span class =codeLinkonclick =Blur(this,this.parentNode.parentNode,getChildren(this),true);>展开 | 选择 | Wrap | 行号


这篇关于形成查询字符串操作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆