$.getJSON(get, function (data) {
if(data.results[0])
{ ver = data.results[0];
$("#result").html(ver);}
else
$("#result").html("This source does not provide the lyrics you want. Try Sources #1 and #2");
});
$.post("check.php", { 'vid': 'gS9o1FAszdk', 'sursa': "1", 'vers':ver } ,function(dt){alert(ver);});
Run Code Online (Sandbox Code Playgroud)
这是我的代码,没有任何影响.如果我从数据中删除'vers',脚本工作正常.怎么了?
因为AJAX是异步的.所以你的post方法不会等待getJSON完成执行并使用中的值ver.你应该将post调用移动到getJSON的回调函数
$.getJSON(get, function (data) {
var ver =""
if(data.results[0])
{ ver = data.results[0];
$("#result").html(ver);
}
else
{
$("#result").html("This source does not provide the lyrics you want. Try Sources #1 and #2");
}
$.post("check.php",
{ 'vid': 'gS9o1FAszdk', 'sursa': "1", 'vers':ver } ,function(dt){
alert(ver);
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
91 次 |
| 最近记录: |