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?

1
  • 1
    By creating the whole URL yourself instead of passing in username as a parameter. Commented Nov 14, 2013 at 13:31

1 Answer 1

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!");
        }
    }
);
Sign up to request clarification or add additional context in comments.

1 Comment

To be correct in theory as well as in practice you also need a call to encodeURIComponent; see stackoverflow.com/q/332872/50079

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.