javascript - How do I parse Url with `&` sign in jquery code? -


i have following code in common.js file.

logic if highlighttextbox if data not matching , removehighlighttextbox if data matching.

url  = /services/getautocompletedata?v=  name = & son  actualurl = /service/getdata?v=my & son&eq=true  //debuge following js code , found above values //here problem because of `&` sign url gets disturb `actualurl /service/getdata?v=my & son&eq=true` //so after `&` sign url gets ignore js (i.e son&eq=true code) //i have passes values `my & son` js parsing `my` how parse original url `&` sign ?  var div = $(this).closest("div"); var elem = div.find(":text"); elem.change(); var name = elem.val(); var actualurl = url + name + "&eq=true" var filter = $(this).attr("filter"); if (name == "") {     div.find(":hidden").val('');     return; } ajaxpostcall(actualurl, filter, function (data) {     if (data == null || data.length != 1) {         highlighttextbox(elem);         div.find(":hidden").val('');         return;     }     removehighlighttextbox(elem)     div.find(":hidden").val(data[0].key);     elem.val(data[0].value); });  function ajaxpostcall(actualurl, extraparam, onsuccess) {     $.ajax({         type: "post",         contenttype: "application/json; charset=utf-8",         url: actualurl,          data: extraparam,         datatype: "json",         success: function (data) { if (onsuccess != null) onsuccess(data); },         error: function (result) { }     }); } 

try this

  var actualurl = encodeuricomponent(url + name + "&eq=true"); 

encodeuricomponent thisfunction encodes uri component.

this function encodes special characters. in addition, encodes following characters: , / ? : @ & = + $ #