Reputation: 3911
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?
Upvotes: 2
Views: 1547
Reputation: 490
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
}
});
Upvotes: 1
Reputation: 943579
Some characters have special meaning in URIs, use encodeURIComponent if you want to use them as data.
Upvotes: 8