0
$.getJSON('<?php echo $this->baseURL()?>/site/ajax/checkusername',
    {username: $('#username').val()},
    function(data) 
    {
        if (data == "TRUE") 
        {
            $("#available").text("This username is available!");
        } 
        else 
        {
            $("#available").text("This username is not available!");
        }
    }
    );

returns a request url of:

http://my.local/site/ajax/checkusername?username=sdfsdf

I would like it to return in the form:

http://my.local/site/ajax/checkusername/username/sdfsdf

How can this be achieved?

tread
  • 10,133
  • 17
  • 95
  • 170
  • 1
    By creating the whole URL yourself instead of passing in `username` as a parameter. – Jon Nov 14 '13 at 13:31

1 Answers1

1
$.getJSON('<?php echo $this->baseURL()?>/site/ajax/checkusername/username/' + encodeURIComponent($('#username').val()),
    function(data) 
    {
        if (data == "TRUE") 
        {
            $("#available").text("This username is available!");
        } 
        else 
        {
            $("#available").text("This username is not available!");
        }
    }
);
Legionar
  • 7,472
  • 2
  • 41
  • 70
  • To be correct in theory as well as in practice you also need a call to `encodeURIComponent`; see http://stackoverflow.com/q/332872/50079 – Jon Nov 14 '13 at 13:32