0

I have looked for a long time but I haven't been able to find a simple solution. On my webpage I want to input an address which will be looked up by a website which returns a webpage where in the text the username I need is located.

https://id.ripple.com/v1/user/ + the username inputed. It would open the page like https://id.ripple.com/v1/user/rUkUchFYfvjucGtGDtSV2avQCzmJrktkVw where there will be a username parameter containing sashadkiselev. I want to be able to make a function which takes the address opens that webpage retrieves the username and shows it in a pop up box.

4
  • this is done with server side scripting, redirecting. Commented Dec 18, 2014 at 22:43
  • you use ajax to fetch that url. read up on ajax, this is a very basic question. Commented Dec 18, 2014 at 22:43
  • 3
    So you already have the username and then you want to query a URL for the username? ... Why? Commented Dec 18, 2014 at 22:47
  • answerers: be aware that id.ripple.com/v1/user/sashadkiselev works Commented Dec 18, 2014 at 22:52

1 Answer 1

1

As redundant as your request seems, if you are using jQuery, you can have the following code to do what you want:

$(function () {
    function getUsername(username, callback) {
        $.getJSON('https://id.ripple.com/v1/user/' + username, function (data) {
            callback.call(data, data.username);
        });
    }

    getUsername('sashadkiselev', function (username) {
        alert('Username is: ' + username);
        // the rest of the data is also available as "this"
    });
});

Note that the ability to pass a function as the callback parameter to getUsername() allows you to easily customise what you do with the username.

Sign up to request clarification or add additional context in comments.

1 Comment

Note that my function current doesn't do any error handling if an error is returned from the URL.

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.