我面临着一些关于我的应用程序和服务器之间交互的困难。我真的希望你能帮助我。我喜欢将JSONP文件提供的用户信息(名称,年龄等)加载到JSON存储中。我怎么处理这个?非常感谢你。
LogIn函数如下所示:
onSigninCommand: function(view, username, password) {
var data1 = username;
var data2 = password;
var me = this;
loginView = me.getLoginView();
if (username.length === 0 || password.length === 0) {
loginView.showSignInFailedMessage('keine eingabe');
return;
}
console.log('Username: ' + username + '\n' + 'Password: ' + password);
Ext.util.JSONP.request({
url: 'http://127.0.0.1:4712/talentcommunity/getuserinfo',
headers: {
'content-type': 'application/x-www-form-urlencoded ; charset=utf-8'
},
method: 'post',
params: {
user: data1,
pw: data2
},
callbackKey: 'callback',
success: function (response) {
console.log(response);
var loginResponse = response;
if (loginResponse.msg == "OK") {
var jsonResponse = Ext.JSON.decode(response.responseText);
XXX.store.MyJsonPStore.loadData(jsonResponse);
me.signInSuccess();
}
else {
loginView.showSignInFailedMessage('token null.');
}
},
failure: function(response) {
loginView.showSignInFailedMessage('token null.');
}
});
商店的定义如下:
Ext.define('xxx.store.MyJsonPStore', {
extend: 'Ext.data.Store',
alias: 'store.myStore',
requires: [
'xxx.model.user'
],
config: {
model: 'xxx.model.user',
storeId: 'myStore',
proxy: {
type: 'jsonp',
url: 'http://127.0.0.1/talentcommunity/getuserinfo',
autoAppendParams: false,
reader: {
type: 'json'
}
}
}
包含JSONP文件的结构如下:
{"msg": "OK",
"user": {
"token": "xyz",
"firstName": "Bertha",
"lastName": "Muster",
"age": "24",
}
}