Sathish
Sathish

Reputation: 2460

append(add) a text in url using jQuery

below code working fine but I need to append option1 in href,

 $(document).ready(function () {
        $("#head_drop .dd-option").click(function () {
            var option = $('.dd-option-value',this).attr('value');
            var option1 = $('.dd-option-text',this).text();
           // alert(option1);
            $.ajax({
                type: 'get',
                url: '<?php echo $this->getBaseUrl();?>categories/index/city/',
                data: {option: option},
                success: function(data) {
                    $(location).attr('href',"<?php echo $this->getBaseUrl()?>");
                }
            });
        });
    });

now its return http://example.com/

I want like http://example.com/option1

I tried $(location).attr('href',"<?php echo $this->getBaseUrl()?>"option1); but failed to get, Thanks...

Upvotes: 0

Views: 128

Answers (2)

Eric Mahieu
Eric Mahieu

Reputation: 327

You have your " at the wrong place, it should read:

$(location).attr('href',"<?php echo $this->getBaseUrl()?>option1");

Upvotes: 0

Jay Blanchard
Jay Blanchard

Reputation: 34416

If option1 is a variable all you need is to concatenate with a + -

$(location).attr('href',"<?php echo $this->getBaseUrl()?>" + option1)

Upvotes: 5

Related Questions