locked
Extract special character from url and arrange using jquery RRS feed

  • Question

  • User1839056048 posted

    Hi following is part of a url

    LekshmiTravels/Places.aspx?fplace=Mumbai%20Central,%20 Mumbai,%20 Maharashtra,%20India&tplace=Vikroli%20Station%20(East),%20Vikhroli%20East,%20Mumbai, %20Maharashtra,%20India,&t1=xyz&dt2=klty

    my requirement is to extract values from this url

    here fplace=Mumbai%20Central,%20 Mumbai,%20 Maharashtra,%20India

    there are 3 comma separator in fplace .i need the last 2 comma separator values means avoid mumbai central

    and fplace should be Mumbai,Maharashtra,India

    and tplace also should last 2 commaseparate values

    ie Mumbai,Maharashtra,India and

    t1=xyz and t2=klty

    How it is possible using jquery

    Regards

    Baiju

    Friday, July 1, 2016 7:10 AM

Answers

  • User61956409 posted

    Hi Baiju,

    following is part of a url

    LekshmiTravels/Places.aspx?fplace=Mumbai%20Central,%20 Mumbai,%20 Maharashtra,%20India&tplace=Vikroli%20Station%20(East),%20Vikhroli%20East,%20Mumbai, %20Maharashtra,%20India,&t1=xyz&dt2=klty

    my requirement is to extract values from this url

    here fplace=Mumbai%20Central,%20 Mumbai,%20 Maharashtra,%20India

    there are 3 comma separator in fplace .i need the last 2 comma separator values means avoid mumbai central

    and fplace should be Mumbai,Maharashtra,India

    and tplace also should last 2 commaseparate values

    ie Mumbai,Maharashtra,India and

    t1=xyz and t2=klty

    How it is possible using jquery

    According to your description, it seems that you’d like to extract data from URL, you could use split(‘&’) to split querystring part of a URL first to get variables value, then you could call String split() method to split the variable.

    http://www.w3schools.com/jsref/jsref_split.asp

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 4, 2016 10:03 AM

All replies

  • User61956409 posted

    Hi Baiju,

    following is part of a url

    LekshmiTravels/Places.aspx?fplace=Mumbai%20Central,%20 Mumbai,%20 Maharashtra,%20India&tplace=Vikroli%20Station%20(East),%20Vikhroli%20East,%20Mumbai, %20Maharashtra,%20India,&t1=xyz&dt2=klty

    my requirement is to extract values from this url

    here fplace=Mumbai%20Central,%20 Mumbai,%20 Maharashtra,%20India

    there are 3 comma separator in fplace .i need the last 2 comma separator values means avoid mumbai central

    and fplace should be Mumbai,Maharashtra,India

    and tplace also should last 2 commaseparate values

    ie Mumbai,Maharashtra,India and

    t1=xyz and t2=klty

    How it is possible using jquery

    According to your description, it seems that you’d like to extract data from URL, you could use split(‘&’) to split querystring part of a URL first to get variables value, then you could call String split() method to split the variable.

    http://www.w3schools.com/jsref/jsref_split.asp

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 4, 2016 10:03 AM
  • User-474980206 posted

    no jQuery required, just plain javascript:

    var query = location.href.split("?")[1];
    var params = {};
    if (query) {
        var p = query.split("&");
        for (var i in p) {
            var args = p[i].split("=");
             params[args[0]] = decodeURIComponent(args[1]);
        }
        // cover place to array removing first element
        params.fplace = params.fplace.split(",").splice(1);
    }
    
    alert(params.fplace);
    alert(params.t1);
    alert(params.dt2); // is dt2 in sample url
    

    Tuesday, July 5, 2016 12:48 AM