JavaScript的 - 如何执行一个简单的GET的WebRequest? [英] javascript - how to execute a simple GET webrequest?
本文介绍了JavaScript的 - 如何执行一个简单的GET的WebRequest?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能在javascript执行一个简单的WebRequest。
如
VAR海峡= * whatever_comes_back_from *(?search.php中术语=你好);
解决方案
您可以使用jQuery或其他JavaScript的,而不是填充变量然后以线性的方式脚本在继续的思想库,但是,你应该考虑的方面回调一次的值的被检索,因为它可以利用时间来检索数据量可变。
架构此事件的JavaScript的功能,是罕见的在其他编程语言。
$。获得('的search.php?长期=你好',功能(数据){
警报(数据)
});
How can I execute a simple webrequest in javascript.
Such as
var str = *whatever_comes_back_from*("search.php?term=hello");
解决方案
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)
});
这篇关于JavaScript的 - 如何执行一个简单的GET的WebRequest?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文