parse the URI using encodeURIComponent() function

If you want to parse your URI then you should have to use 

encodeURIComponent() function

problem – 

I have following code in common.js file.

logic is if HighlightTextBox if data is not matching and RemoveHighlightTextBox if data is matching.

url  = /Services/GetAutoCompleteData?v=

name = My & Son

actualUrl = /Service/GetData?v=My & Son&eq=true

//debuge following js code and found above values
//here problem is because of `&` sign url gets disturb as `actualUrl is /Service/GetData?v=My & Son&eq=true`
//so after `&` sign url gets ignore by js (i.e Son&eq=true code)
//i have passes values `My & Son` but actually js parsing it as `My` so how do I parse my original URL with `&` sign ?

var div = $(this).closest("div");
var elem = div.find(":text");
var name = elem.val();
var actualUrl = url + name + "&eq=true"
var filter = $(this).attr("filter");
if (name == "") {
AjaxPostCall(actualUrl, filter, function (data) {
    if (data == null || data.length != 1) {

function AjaxPostCall(actualUrl, extraParam, onSuccess) {
        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) { }

Solution -
  var actualUrl = encodeURIComponent(url + name + "&eq=true");
which will parse an URI


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s