Passing ampersands in Javascript through AJAX
I am making an AJAX call with JQuery to a .Net application. The value that is being passed sometimes to my ajax call is &.
var searchValue = '&';
var url = "method=searchvariables&searchvalue="+searchValue;
url += "&position=1"开发者_运维技巧;
On the .NET side, the searchVale is always null.
How do I pass in the ampersand so it gets recognized by the .Net code?
Some characters have special meaning in URIs, use encodeURIComponent if you want to use them as data.
You can leverage jQuery to build the query string by passing a data
object. That will take care of encodeURIComponent
for you
$.ajax(URL, {
data: {
method : searchvariables,
searchvalue : searchValue,
position : 1
}
});
精彩评论