Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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_Jquery_Html - Fatal编程技术网

Javascript 在请求期间生成可用的URL

Javascript 在请求期间生成可用的URL,javascript,jquery,html,Javascript,Jquery,Html,我正在通过jQuery执行ajax请求,例如,我的URL是http://test.com/query.php?hello=foo 条形码 但是,请求只接受http://test.com/query.php?hello=foo。我如何使它占用更多的空间?和特殊字符实体,如&,-,,等等 谢谢 我如何使它占用更多的空间 通过适当的空间: http://test.com/query.php?hello=foo+bar 或: 和特殊字符实体,如&、-、!,等等 都一样。确保正确地对它们进行url编码:

我正在通过
jQuery
执行
ajax
请求,例如,我的URL是
http://test.com/query.php?hello=foo 条形码

但是,请求只接受
http://test.com/query.php?hello=foo
。我如何使它占用更多的空间?和特殊字符实体,如
&
-
,等等

谢谢

我如何使它占用更多的空间

通过适当的空间:

http://test.com/query.php?hello=foo+bar
或:

和特殊字符实体,如&、-、!,等等

都一样。确保正确地对它们进行url编码:

  • &
    =>
    %26
  • -
    =>
    -
    (不需要编码)
  • =>
    (不需要编码)
为了在javascript中正确执行此操作,可以使用函数

或者,如果您使用jQuery,您还可以查看该方法

最后,如果使用jQuery发送AJAX请求,可以执行以下操作:

$.ajax({
    url: 'query.php',
    type: 'GET',
    data: { hello: 'foo bar' },
    success: function(result) {
        ...
    }
});

jQuery将负责对
数据中传递的查询字符串参数进行正确的url编码。

您可以执行
编码URI(URI)

有关更多信息,请访问此链接

$.ajax({
    url: 'query.php',
    type: 'GET',
    data: { hello: 'foo bar' },
    success: function(result) {
        ...
    }
});