【发布时间】:2009-03-26 00:17:17
【问题描述】:
我正在学习 jquery 并写了这个,所以我可以对一个 php 文件执行两个单独的 $.GET,检索一些信息并对其进行一些计算。我知道我可以创建一个特定的 php 文件来执行所有操作并返回我需要的值,但我认为在我需要检索信息的任何时候重用这个 php 文件会更有意义。
我在一个函数中有这个,我不确定如何执行第一个 $.GET,等待它完成,将它附加到一个变量,然后执行第二个 $.GET 将变量传递给它并执行计算。相反,我将它们嵌套在一起,我认为这是不正确的。这是代码。
$.get("selectdb.php", { 'id':nsname, 'q':'basecomplexity','table':'switchers' }, function(data)
{
$('#switchtotal'+lastIndex).html(data); //sets data to #switchtotal
$.get("selectdb.php", { 'id':nsname, 'q':'sources','table':'switchers' }, function(data)
{
var val1 = $('#switchtotal'+lastIndex).html();
var answer = ((parseFloat(nszones)*parseFloat(data))+parseFloat(val1))*parseFloat(nsquant);
$('#switchtotal'+lastIndex).html(answer.toFixed(2)); //calculates formula and displays
});
});
有更简单的方法吗?
【问题讨论】: