开发者

What are the characters I can use in jQuery.ajax?

I am making a website that sends with jQuery.ajax a lot of information which is inside many inputs. In order to be able to send this ajax with any character in the inputs, I want to replace the values I send to something that can be sent via ajax. So for this I need to know which characters I can send and which c开发者_高级运维haracters I can't.


You don't need to care about which characters. Jquery encodes them for you. For example, if you do:

$.ajax({
   url: "your_url",
   data: {
      name: $("#txtName").val(),
      lastName: $("#txtName").val(),
   }
});

$.ajax will urlencode your 'name' and 'lastName' params automagically, so you don't have to care.

Any character can be sent.

Cheers


There are no restrictions on which characters can be sent via HTTP requests. However, you do need to encode your input values. How you do this depends on how exactly you're making the requests. If you're doing an HTTP GET and are placing the values in the query string, you should use encodeURIComponent. This is required because this isn't a valid URL:

/MyAjaxMethod?data=This Is a String

but this is:

/MyAjaxMethod?data=This%20Is%20a%20String

If you are doing an HTTP POST with form values or JSON, then jQuery will encode the data for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜