1

How can I execute a simple webrequest in javascript.

Such as

var str = *whatever_comes_back_from*("search.php?term=hello");
1

2 Answers 2

4

This is usually handed via XMLHttpRequest, usually abstracted via a library that irons out the differences between browsers (bigger libraries that do lots of other stuff include YUI and jQuery).

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

Comments

2

You could use jQuery, or another javascript library, but instead of thinking of populating the variable then continueing with the script in a linear way, you should think in terms of a callback once the value is retrieved, because it can take a variable amount of time to retrieve the data.

This event based architecture is a feature of javascript that is rare in other programming languages.

$.get('search.php?term=hello', function(data){
    alert(data)
});

Comments

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.