Sencha使用JSONP格式触摸Ajax登录 [英] Sencha touch Ajax Login using JSONP format
本文介绍了Sencha使用JSONP格式触摸Ajax登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var formPanel = Ext.create('Ext.form.Panel', {
fullscreen: true,
items: [{
xtype: 'fieldset',
items: [
{
xtype: 'emailfield',
name : 'email',
label: 'Email'
},
{
xtype: 'passwordfield',
name : 'password',
label: 'Password'
}
]
}]
});
formPanel.add({
xtype: 'toolbar',
docked: 'bottom',
layout: { pack: 'center' },
items: [
{
xtype: 'button',
text: 'Login',
handler:function(){
Ext.util.JSONP.request({
url: 'http://indianleafsol.com/Prasad/api/callback.php',
params:{username:'root',
password:'root',
callback: 'callback'
// scope: this,
},
callback: function(response) {
alert("hi");
//console.log("checklogin success");
if (response.success == true)
{
alert("hi1");
}
else {
alert("hi error");
Ext.Msg.alert('', response.errors.reason, '');
console.log("failure");
}
}
});
}
},
{
xtype: 'button',//http://indianleafsol.com/Prasad/api/categorylist.php
text: 'Get Data',
handler: function() {
Ext.create('Ext.DataView', {
fullscreen: true,
store: {
autoLoad: true,
fields: ['id', 'name'],
proxy: {
type: 'jsonp',
url: '//http://indianleafsol.com/Prasad/api/categorylist.php?callback=t',
reader: {
type: 'json',
root: 'categories'
}
}
},
tpl: [
'<tpl for=".">',
'<div>',
'<h2>{id}</h2>',
'<p>{name}</p>',
'</div>',
'</tpl>'
],
//itemTpl: '<h2>{id}</h2><p>{name}</p>',
});
// Load User 1 and do something with it (performs a GET request to /users/1)
// Ext.Msg.alert('Form Values', JSON.stringify(formPanel.getValues(), null, 2));
}
},
{
xtype: 'button',
text: 'Clear Data',
handler: function() {
formPanel.reset();
}
}
]
});
这里登录失败;
我的PHP代码:
here login fail;
my php code:
<?php $callback = $_REQUEST['callback'];
//$call1 = $_REQUEST['username'];
//$call2 = $_REQUEST['password'];
// Create the output object.
$output = $result = array("Data"=>array("id"=>"1",
"name"=>"categories_name"));
//$callback="callback";
//start output
$username=$_REQUEST["username"];
$password=$_REQUEST["password"];
if($username=="root" && $password=="root"){
if ($callback) {
header('Content-Type: text/javascript');
echo $callback . '('.'{"success":true,' . json_encode($output) . '});';
}
/* else {
//header('Content-Type: application/x-json');
echo $callback . '('.'{"success":false,' . json_encode($output) . '});';
}
*/
//echo $callback . '('.'{"success":false,' . json_encode($output) . '});';
}
else{
echo $callback . '('.'{"success":false,' . json_encode($output) . '});';
}
?>
终于回复得到hi,
请帮帮我
热烈的谢谢。
finally response getting "hi" only ,
please help me
warm thanks.
推荐答案
回调 =
callback =
_REQUEST [' 回调'跨度>];
//
_REQUEST['callback']; //
call1 =
这篇关于Sencha使用JSONP格式触摸Ajax登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文