0

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);
        }
    });
});
1

2 Answers 2

2

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

url: '/profile/timeline/post/'+slug+'/?'+filtertype,
Sign up to request clarification or add additional context in comments.

2 Comments

I see, let me check more
Can you make sure that the value of slug is not "%20slug%20" ? I mean can you console.log it before making the ajax?
1

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}`

3 Comments

i get the wrong URL, /profile/timeline/post/%20slug%20?filtertype
If using es6 feature, make sure you are using tilde apostrophe (`) its not the same as regular apostrophe ('). - Tilde - key under ESC Upper example should work without any problem using regular js concating. Please make sure you have correct values inside variables
that was my mistake in php, sorry

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.