slickness
slickness

Reputation: 246

How can i add variable to URL

How can I insert two variables to the URL in the code? I have already inserted the variable filtertype at the end of the URL. The word "slug" in the url should be replaced by the variable slug.

$('body').on('click','.profile-filter',function(e) {
    e.preventDefault();
    var filtertype = $(this).data("filtertype");
    var slug = $(this).data("slug");

    $.ajax({
        type: 'GET',
        url: '/profile/timeline/post/slug/?' +filtertype,
        success: function (data) {
            $('#profile_content').html(data);
        },
        error: function (xhqr, data) {
            _toastr_new(data, "top-full-width", "error", false, '.toastr-notify', 0);
        }
    });
});

Upvotes: 0

Views: 74

Answers (2)

noitse
noitse

Reputation: 1045

Hmm I guess you want to concat strings, you can use pure js like this

'/profile/timeline/post/'+ slug +'/?' + filtertype 

Or use ES6 template literal feature

`/profile/timeline/post/${slug}/?${filterType}`

Upvotes: 1

Abhay Maurya
Abhay Maurya

Reputation: 12277

Not sure if I am understanding the question right, but simple Javascript concatenation won't work? like so:

url: '/profile/timeline/post/'+slug+'/?'+filtertype,

Upvotes: 2

Related Questions