jQuery的$。阿贾克斯URL编码问题 [英] jQuery's $.ajax URL Encoding Problems

查看:113
本文介绍了jQuery的$。阿贾克斯URL编码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery的$。阿贾克斯的方法来发送和检索数据,以REST服务。一些URL的我提供的$就法需要空格和其它特殊字符是EN codeD。

I'm using jQuery's $.ajax method to send and retrieve data to a REST service. Some of the URL's I'm providing to the $.ajax method requires spaces and other special characters to be encoded.

问题在于浏览器,Safari浏览器(的Webkit)和Internet Explorer浏览器。火狐邮政的一个URL是连接codeD,但其他浏览器张贴到URL这是不连接codeD。

The problem lies with Chrome, Safari (Webkit) and Internet Explorer browsers. Firefox POST's to a URL which is encoded but the other browsers POST to a URL which isn't encoded.

作为一个例子:

$.ajax ({
  url: "http://localhost:8080/rest/123/Product Line A/[Product Type B]",
  type: "POST",
  dataType: "json",
  data: { ... },
  success: function(...){},
  error: function(...){}
})

Firefox的帖子在以下格式的网址:

Firefox POSTS the URL in the following format:

http://localhost:8080/rest/123/Product%20Line%20A/%5BProduct%20Type%20B%5D

Chrome浏览器,Safari和IE浏览器的帖子的网址中的格式如下:

Chrome, Safari and IE POSTS the URL in the following format:

http://localhost:8080/rest/123/Product Line A/[Product Type B]

在REST服务接受EN codeD(火狐)格式 - 有没有办法可以让在所有浏览器

The REST services accepts the encoded (Firefox) format - is there a way I can make this consistent across all browsers?

在此先感谢!

推荐答案

您可以使用JavaScript的EN codeURI()函数来恩codeA网址为火狐格式为你的国家。

You can use javascript's encodeURI() function to encode a url into "Firefox format" as you state.

这篇关于jQuery的$。阿贾克斯URL编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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