制作一个URL符合W3C标准和工作在Ajax请求 [英] Making a URL W3C valid AND work in Ajax Request

查看:124
本文介绍了制作一个URL符合W3C标准和工作在Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通用的函数,返回的URL。 (这是一个插件函数返回一个插件中的URL资源[图片,样式])。

I have a generic function that returns URLs. (It's a plugin function that returns URLs to resources [images, stylesheets] within a plugin).

我用这些URL GET参数。

I use GET parameters in those URLs.

如果我想在一个HTML页中使用这些URL,通过W3C验证,我需要掩盖和号为&放大器;放大器;

If I want to use these URLs within a HTML page, to pass W3C validation, I need to mask ampersands as &

/plugin.php?plugin=xyz&resource=stylesheet&....

但是,如果我想使用的网址为URL参数为一个AJAX调用,该符号不正确PTED,拧紧了我的电话间$ P $。

but, if I want to use the URL as the "url" parameter for a AJAX call, the ampersand is not interpreted correctly, screwing up my calls.

我做一些事情得到和放大器;放大器;在AJAX的工作需要?

我非常希望避免增加参数TH URL生成功能(intendedUse =AJAX或其他)或操纵JavaScript中的URL,因为这个插件模式将被很多人重复使用很多次(也可能是),我希望它尽可能的简单。

I would very much like to avoid adding parameters to th URL generating function (intendedUse="ajax" or whatever) or manipulating the URL in Javascript, as this plugin model will be re-used many times (and possibly by many people) and I want it as simple as possible.

推荐答案

在我看来,你正在运行成具有一体成型的应用程序跨多个层的问题。在这种情况下,它是该插件。

It seems to me that you're running into the problem of having one piece of your application cross multiple layers. In this case it's the plugin.

指出,一个URL应使用<$所指定的 RFC 1738的URL C $ C>&安培; 标记,以键/值对彼此分离。然而符号是HTML保留令牌,因此应逃进&放大器;放大器; 。由于逃避&号是HTML的一个神器,你的插件可能不应直接逃避它们。相反,你应该有一个函数或一些逃脱的规范网址,以便它可以嵌入HTML标记。

A URL as specified by RFC 1738 states that a URL should use a & token to separate key/value pairs from one another. However ampersand is a reserved token in HTML and therefore should be escaped into &amp;. Since escaping the ampersands is an artifact of HTML, your plugin should probably not be escaping them directly. Instead you should have a function or something that escapes a canonical URL so that it can be embedded in HTML markup.

这篇关于制作一个URL符合W3C标准和工作在Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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