<script type="text/javascript">
Ext.onReady(function() {
Ext.QuickTips.init();
nombre = '';
function doAjax(){
Ext.Ajax.request({
url : 'log.php',
// method: 'GET',
success: function( resp ){
var jsonData = Ext.util.JSON.decode(resp.responseText);
return(jsonData.user);
},
failure: function ( result, request ) {
var jsonData = Ext.util.JSON.decode(result.responseText);
var resultMessage = jsonData.data.result;
fn_AKExt(resultMessage, 'Error');
}
});
}
var data = {
name: doAjax(),
company: 'Ext JS, LLC',
address: '4 Red Bulls Drive',
city: 'Cleveland',
state: 'Ohio',
zip: '44102',
kids: [{
name: 'Sara Grace',
age:3
},{
name: 'Zachary',
age:2
},{
name: 'John James',
age:0
}]
};
var p2 = new Ext.Panel({
title: 'XTemplate',
width: 300,
html: '<p><i>Apply the template to see results here</i></p>',
tbar: [{
text: 'Apply Template',
handler: function(){
var tpl = new Ext.XTemplate(
'<p>Name: {name}</p>',
'<p>Company: {company}</p>',
'<p>Location: {city}, {state}</p>',
'<p>Kids: ',
'<tpl for="kids" if="name==\'Jack Slocum\'">',
'<tpl if="age > 1"><p>{}. {parent.name}\'s kid - {name}</p></tpl>',
'</tpl></p>'
);
tpl.overwrite(p2.body, data);
p2.body.highlight('#c3daf9', {block:true});
}
}],
renderTo: document.body
});
});
</script>
<?php session_start();
$data=array (
"success" => true,
"user" => $_SESSION['name']
);
//var_dump($data);
echo json_encode($data);
?>
Ext.Ajax.request({
url: 'aqui_tu_php.php',
params : {
//parametros que quieras enviar a tu pagina php
miparametro : 'el valor de mi parametro'
},
scope : this,
success : function(response){
//el success es cuando efectivamente dio con la pagina
//en la variable response o como quieras colocarle
//se devuelve todo tu JSON
//aqui por ejemplo se lo asigno y decodifico a una variable que llamo info
info = Ext.decode(response.responseText);
//aqui pergunto si el valor de success es false
//para devolverel al usuario un error personalizado
if (info.success === false){
Ext.Msg.show({
title : 'ERROR',
msg : 'mi mensaje!',
icon : Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK,
fn : function(){
//cualquier cosa que quieras despues del error
});
}
});
}else{
//si el valor de success es true entonces hago algo con los valores almacenados en
// info, prueba hacer un console.debug(info) y veras como se almacenan tus datos.
}
},
failure: function(response){
//aqui es por si no te logro conectar o dio un error, no tiene relación con el
// {"success": false}
}
function joAjax(){
Ext.Ajax.request({
url: ajax.php
success:funciont(resp){
var jsonData= Ext.decode(resp.responseText);// hasta aqui estamos bien yo obtengo mi valor o el que necesito, de hecho hago un alert(jsonData.user) , y me da el msg mostrandome el usuario
//pero yo necesito es esto
nombre = jsonData.user; aqui le asigno el valor a la variable nombre
},
scope:this
});
};
var data = {
name = nombre //aqui es donde me da el error, acoto lo de scope:this no lo sabia lo acabo de poner ahorita pero es algo que no entiendo mucho
}
<script type="text/javascript">
Ext.onReady(function() {
Ext.QuickTips.init();
/*function doAjax(){
Ext.Ajax.request({
url : 'log.php',
// method: 'GET',
success: function( resp ){
var jsonData = Ext.util.JSON.decode(resp.responseText);
nombre = jsonData.user;
alert(nombre);
},
failure: function ( result, request ) {
var jsonData = Ext.util.JSON.decode(result.responseText);
var resultMessage = jsonData.data.result;
fn_AKExt(resultMessage, 'Error');
},
scope:this
});
}*/
var data = {
name: '',
company: 'Ext JS, LLC',
address: '4 Red Bulls Drive',
city: 'Cleveland',
state: 'Ohio',
zip: '44102',
kids: [{
name: 'Sara Grace',
age:3
},{
name: 'Zachary',
age:2
},{
name: 'John James',
age:0
}]
};
var p2 = new Ext.Panel({
title: 'XTemplate',
width: 300,
html: '<p><i>Apply the template to see results here</i > < /p>',
tbar: [{
text: 'Apply Template',
handler: function () {
Ext.Ajax.request({
url: 'log.php',
// method: 'GET',
success: function (resp) {
var jsonData = Ext.util.JSON.decode(resp.responseText);
data.name = jsonData.user;
var tpl = new Ext.XTemplate('<p>Name: {name}</p>', '<p>Company: {company}</p>', '<p>Location: {city}, {state}</p>', '<p>Kids: ', '<tpl for="kids" if="name==\'Jack Slocum\'">', '<tpl if="age > 1"><p>{}. {parent.name}\'s kid - {name}</p></tpl>', '</tpl></p>');
tpl.overwrite(p2.body, data);
p2.body.highlight('#c3daf9', {
block: true
});
},
failure: function (result, request) {
var jsonData = Ext.util.JSON.decode(result.responseText);
var resultMessage = jsonData.data.result;
fn_AKExt(resultMessage, 'Error');
}
});
}
}],
renderTo: document.body
});
});
</script>
function doAjax(){
Ext.Ajax.request({
url : 'log.php',
// method: 'GET',
success: function( resp ){
var jsonData = Ext.util.JSON.decode(resp.responseText);
createPanel(jsonData); //LE ENVIAS EL OBJETO CON TODOS LOS CAMPOS
},
failure: function ( result, request ) {
var jsonData = Ext.util.JSON.decode(result.responseText);
var resultMessage = jsonData.data.result;
fn_AKExt(resultMessage, 'Error');
}
});
}
function createPanel(info){
var data = {
name: info.nombre,
company: 'Ext JS, LLC', //info.company
address: '4 Red Bulls Drive', //info.address
city: 'Cleveland',
state: 'Ohio',
zip: '44102',
kids: [{
name: 'Sara Grace',
age:3
},{
name: 'Zachary',
age:2
},{
name: 'John James',
age:0
}]
};
var p2 = new Ext.Panel({
title: 'XTemplate',
width: 300,
html: '<p><i>Apply the template to see results here</i></p>',
tbar: [{
text: 'Apply Template',
handler: function(){
var tpl = new Ext.XTemplate(
'<p>Name: {name}</p>',
'<p>Company: {company}</p>',
'<p>Location: {city}, {state}</p>',
'<p>Kids: ',
'<tpl for="kids" if="name==\'Jack Slocum\'">',
'<tpl if="age > 1"><p>{}. {parent.name}\'s kid - {name}</p></tpl>',
'</tpl></p>'
);
tpl.overwrite(p2.body, data);
p2.body.highlight('#c3daf9', {block:true});
}
}],
renderTo: document.body
});
}
doAjax(); //Inicias todo el proceso
It looks like you're new here. If you want to get involved, click one of these buttons!
The content of this site is copyrighted by Quizzpot.com, it is prohibited to publish our tutorials on other blogs, magazines or any other media without prior permission.
Copyright © 2012 Quizzpot.
Our visitors are mostly developers and Web designers, advertise with us, you only need to contact us .