【发布时间】:2021-01-01 23:46:34
【问题描述】:
我想在启动功能中发送 Ajax 请求,并根据响应打开登录窗口或主窗口。
应用程序.js
launch: function () {
debugger;
Ext.Ajax.request({
url: 'php/foo.php',
params: {
email: 'test@gg.com',
password: '12345',
},
success: function(response, opts){console.log('OK');},
failure: function(response, opts){console.log('ERROR');},
});
debugger;
console.log('This should be printed after Ajax response (either OK/ERROR)');
debugger;
foo.php
<?php
$login=$_POST['email'];
$pass=$_POST['password'];
$result = array();
echo json_encode(array(
"success" => $pass=="123456",
"data" => $result
));
但是,我注意到 Ajax 调用的响应在函数结束之前还没有准备好(图 1)
【问题讨论】: