Javascript Sencha Touch中带有验证和确认消息框的联系表
我正在使用Sencha Touch 2开发我的第一个应用程序,并且我的代码在官方网站上有很强的基础。 与入门教程类似(我没有更改代码),在app.js中,当我提交名为contact.php的表单时:Javascript Sencha Touch中带有验证和确认消息框的联系表,javascript,sencha-touch-2,Javascript,Sencha Touch 2,我正在使用Sencha Touch 2开发我的第一个应用程序,并且我的代码在官方网站上有很强的基础。 与入门教程类似(我没有更改代码),在app.js中,当我提交名为contact.php的表单时: // Sends an AJAX request with the form data to the url specified above (contact.php). // The success callback is called if we get a non-e
// Sends an AJAX request with the form data to the url specified above (contact.php).
// The success callback is called if we get a non-error response from the server
form.submit({
success: function() {
// The callback function is run when the user taps the 'ok' button
Ext.Msg.alert('Mail received', 'We will reply soon', function() {
form.reset();
});
},
});
但是,我修改了contact.php,以便在满足条件时输出json消息:
<?php
if ($_POST[email] != NULL) {
print '{"success": true}';
}
?>
现在,如果php以JSON格式输出success:true,则app.js将显示一条警报消息(请参见上面的代码)“Mail received”。否则将不显示任何消息
但是,如果我想在contact.php中添加其他可能触发不同消息的情况,我将如何在app.js中实现它们?
例如,如果我使用以下内容修改contact.php:
<?php
if ($_POST[email] != NULL) {
print '{"success": true}';
} else {
print '{"wrongemail":true"}';
}
?>
我如何在app.js中实现这一点,以便显示不同的警报(例如,“您的电子邮件地址无效或为空”)
提前感谢您在表单上添加一个“失败”处理程序。submit()调用: