Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript URL的错误检测算法_Javascript_Html_Algorithm_Web_Error Handling - Fatal编程技术网

Javascript URL的错误检测算法

Javascript URL的错误检测算法,javascript,html,algorithm,web,error-handling,Javascript,Html,Algorithm,Web,Error Handling,我想知道一些关于如何实现URL错误检测算法的可能想法。我的url可以按如下方式工作: http://changes.html?Type=Production&Item=Tires&Type=Winter My Url can have the following forms: http://changes.html?Type=Production //which gets you to the base page http://changes.html?Type=Produ

我想知道一些关于如何实现URL错误检测算法的可能想法。我的url可以按如下方式工作:

http://changes.html?Type=Production&Item=Tires&Type=Winter

My Url can have the following forms:

http://changes.html?Type=Production //which gets you to the base page

http://changes.html?Type=Production&Item=Tires //which gives you all the tire options

http://changes.html?Type=Production&Item=Tires&Type=Winter //which gives you a specific tire
我这里的问题是,如果我把Type=Production拼写错了,以至于我把它拼写为Tzxpe=Poductaion,那么我可能会考虑使用默认页面。此外,如果您输入以下URL,请说明所有内容都是正确的:


http://changes.html?Type=Production&Item=Tires&TZAe=Wter 然后,我在考虑只切断轮胎上的绳子,直到它正确为止,然后编程一个页面,重新指向工作部分。我的解决方案似乎有点奇怪和低效。有没有更好的方法来修复URL本身,或者更好地实现我的想法,或者完全不同的方法来解决这个问题?错误检查对于这个项目来说是必须的,所以仅仅收到一个错误的url消息并不能阻止它

也许我误解了您的问题,但您可以做的是将您在后端收到的URL拆分为?=和&然后对照可能的正确值检查Type的值一个enum类或一个预定义的可能性数组,以及与Item相同的值。这取决于您如何处理服务呼叫


我不知道正则表达式是否完全是个好主意。您希望确保拼写正确,但根据我的经验,这并不符合正则表达式。

为什么错误检查如此重要?通常,这些URL肯定不会直接输入到工具栏上?您可以使用regExp吗?我的选项来自一个数据库,该数据库包含大约10000+个每天递增的值。@user3767481检查数据库是您最好的选择,否则您所说的似乎是拼写检查算法