将查询字符串日期参数添加到链接的URL [英] Adding query string date parameters to linked URL

查看:137
本文介绍了将查询字符串日期参数添加到链接的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为网球俱乐部工作,需要在我们的页面上创建一个按钮,将用户发送到我们的预订系统。问题是URL以查询字符串参数结束,http://../../boka_reserve_reg_client_app.php?sess_adm_club_id = 25& YEAR = 2016& MONTH = 04& DAY = 26。



如果我在第一个&之前裁剪网址你仍然可以访问预订页面,但它没有任何功能。



所以我需要的是一个表格,提交参数到结尾用户键入年份,月份和日期的URL或每天生成具有正确日期的新链接的代码。



这是否可以修复用PHP? JavaScript绝对没问题。



谢谢!



我的尝试:



我试图链接到最后没有查询字符串的URL。

I'm working for a tennisclubb and need to create a button on our page that sends the user to our booking system. The thing is that the URL ends with query string parameters, http://../../boka_reserve_reg_client_app.php?sess_adm_club_id=25&YEAR=2016&MONTH=04&DAY=26.

If I crop the URL right before the first "&" you will still be able to access the booking page but it will not have any function.

So what I need is a form that submits the parameters to the end of the URL where the user types the year, month and day or a pice of code that generates a new link every day with the correct date.

Is this possible to fix without using PHP? JavaScript is absolutely fine.

Thanks!

What I have tried:

I tried to link to the URL without the query string at the end.

推荐答案

问题,关于你的不使用PHP,没有意义,它看起来像。



如果你使用URI中的查询部分传递一些数据,你显然这样做是为了在服务器端处理这些数据。如果它是PHP,你用PHP处理它。如果没有,您根本就没有这些查询参数。这不合逻辑吗?



因此,在这种方法中,JavaScript完全无关紧要,即使你实际上使用它来计算一些URI字符串并重定向页面使用它。无论你在客户端做什么都没关系,关键是什么是查询参数以及如何使用它们。所以,忘记不使用PHP,除非你想切换到其他服务器端技术:-)。



有两个明显的解决方案:



第一种方法是:修改服务器端代码以分析查询字符串并接受任何随机查询字符串,并相应地处理它。它会起作用,但这很难看。它只适用于某些情况,当您可以清楚地解释用户出了什么问题。比如,如果您的页面是由作为查询字符串参数传递的笑话号码检索的笑话集合,您可以说笑话号码#1000203230尚不存在并显示您的默认笑话:-)。

在更敏感或更复杂的情况下,最好摆脱这种低技术的方法。



所以,第二个方法是完全摆脱那些查询字符串。这实际上是一个好主意。首先,请记住,即使查询字符串参数也没有真正缩进以便用户输入文本(尽管我做了这些事情,但这不是开发人员的意图)。如果此类输入可能令人困惑或功能不佳,请完全隐藏此信息渠道;它不合适。因此,即使查询字符串,用户也不会输入此数据;该字符串是由于某些用户点击页面或其他输入事件而形成的 - 在页面上,而不是在地址行中输入内容。



所有你需要的是在HTTP请求中发送数据。对于用户,HTTP请求的可见部分仅是地址行。不要在那里传递任何参数,将它们传递到HTTP打包的正文中。基本上,在HTML中,它以两种方式之一完成:Web表单或Ajax。我不知道你是否可以合理地使用表格;这取决于你的HTML设计,如果没有,你可以随时使用Ajax。这就是JavaScript发挥作用的地方。



您是否已经忘记了不更改服务器部分的想法?我确定你有,因为你需要编写适当的服务器端来处理来自表单或Ajax的HTTP请求。 :-)



参见,例如:

PHP和AJAX [ ^ ],

PHP:处理表格 - 手册 [ ^ ]。



-SA
The question, concerning your "without using PHP", makes no sense, it looks like.

If you use the query part in your URI to pass some data, you obviously do it to process this data on the server side. If it is PHP, you handle it with PHP. If you did not, you would not have these query parameters at all. Isn't that logical?

Therefore, in this approach, JavaScript is totally irrelevant, even if you actually use it, say, to calculate some URI strings and redirect the page using it. It doesn't matter what you do on the client side, it just matters what are the query parameters and how they are used. So, forget "without using PHP", unless you want to switch to some other server-side technology :-).

There are two obvious solutions:

First approach would be: modify server-side code to analyze the query string and accept any random query string, handling it accordingly. It will work, but this is ugly. It works only in certain cases, when you can clearly explain the user what is wrong. Say, if your page is a collection of jokes retrieved by a joke number passed as a query string parameter, you can say "Joke number #1000203230 does not exist yet" and show your "default joke" :-).
In more sensitive or complicated cases, it would be much better to get rid of this "low-tech" approach at all.

So, the second approach is to get rid of those query strings at all. This is actually a good idea. First of all, remember that even the query string parameters are not really indented for entering as text by the users (I do such things though, but this is not the developer's intentions). If such entering can be confusing or otherwise poorly functional, hide this information channel completely; it's not suitable. So, the user does not enter this data even in case of query strings; the string is formed as a result of some user's clicks in the page or other input events — on the page, not entering something in the address line.

All you need is to send data in HTTP request. For the user, the visible part of HTTP request is only the address line. Don't pass any parameters there, pass them in the body of the HTTP packed. Basically, in HTML it's done in one of two ways: a Web form or Ajax. I don't know if you can reasonably use the form; it depends on your HTML design, if not, you can always use Ajax. And this is where JavaScript comes into play.

Have you already forgotten the idea of not changing the server part? I'm sure you have, because you need to write proper server side to handle HTTP request from a form or Ajax. :-)

See, for example:
PHP and AJAX[^],
PHP: Dealing with Forms — Manual[^].

—SA


这篇关于将查询字符串日期参数添加到链接的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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