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!");
        }
    }
    );

返回一个请求 url:

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

我希望它以以下形式返回:

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

如何做到这一点?

4

1 回答 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!");
        }
    }
);
于 2013-11-14T13:31:21.563 回答