PDA

View Full Version : How to use ajax directly?



finian
19 May 2007, 6:48 PM
Hi all,

how can i use ajax directly not by using UpdateManager?
i just wanna fetch some results from the server(in json format) and dont want to update any Element.

jsakalos
19 May 2007, 6:57 PM
Try something like this:



new Ext.data.Connection().request({
url: '.....'
, method: 'post' // or get
, scope: this
, params: {
// your params here
}
, callback: function(options, bSuccess, response) {
var o = Ext.decode(response.responseText);
if('object' != typeof o) {
throw 'Invalid server response';
}
if(true === o.success) {
// something useful
}
else {
// handle error
}
}
});

JasonMichael
19 May 2007, 8:01 PM
Hi, this looks pretty good.

Upon success, would the server respond with '1' to indicate true?

finian
19 May 2007, 8:08 PM
jsakalos, thanks so much:) it works.

btw,'cause the Ext.decode() may throw a SyntaxError exception, so maybe it's better to use:


try
{
var o = Ext.decode(response.responseText);
}
catch ( e )
{
alert('Invalid server response');
}

finian
19 May 2007, 8:12 PM
Hi JasonMichael.
it depends on what your server output json look like. you can use any json propertis what ever you want.


{success:1, ...} or {s:1, ...}

JasonMichael
19 May 2007, 8:13 PM
Nevermind, I found the answer here:

http://extjs.com/forum/showthread.php?t=6475&highlight=success%3A

I'm not using JSON at the moment, but I really like this solution. I think I understand what I'm doing wrong, also.

thanks!

jsakalos
20 May 2007, 1:20 AM
jsakalos, thanks so much:) it works.

btw,'cause the Ext.decode() may throw a SyntaxError exception, so maybe it's better to use:


try
{
var o = Ext.decode(response.responseText);
}
catch ( e )
{
alert('Invalid server response');
}

Yes, that's true.

jsakalos
20 May 2007, 1:24 AM
Hi JasonMichael.
it depends on what your server output json look like. you can use any json propertis what ever you want.


{success:1, ...} or {s:1, ...}

Yes, this is true. There is just one factor that is against {success:1} and that is that another Ext code is picky about type of property success and the condition uses to be



if(true === o.success) {
...
}


To keep your server side consistent it's better to adhere to Ext standard as for Ext neither {success:1} nor {success:"true"} would work.

faris
12 Jul 2007, 2:41 AM
hi, i want invoke Connection.js from my js file with the url and value like this
for ex filephp.php?id=

MR jsakalos i need your help pls

evant
12 Jul 2007, 2:46 AM
http://extjs.com/deploy/ext/docs/output/Ext.Ajax.html

faris
12 Jul 2007, 2:54 AM
I want send value to the php file via Connection.js where can i but it:-?

faris
12 Jul 2007, 2:57 AM
http://extjs.com/deploy/ext/docs/output/Ext.Ajax.html

i want to send value with my url to Connection.js where can id do that :-? :-? :-? :-? :-? :-? :-? :-? :-?

faris
12 Jul 2007, 3:02 AM
http://extjs.com/deploy/ext/docs/output/Ext.Ajax.html

i want send value with my url via my jscript to Connection.js how??:-?:-?:-?:">:D

evant
12 Jul 2007, 3:09 AM
I gave you the link for a reason, for you to read.

However, something like



Ext.Ajax.request(
{
url: 'whatever.php',
params: {id: 1},
callback: function(options, success, response)
{
if (success)
alert(response.responseText);
}
}
);

faris
12 Jul 2007, 3:16 AM
ext-all.js 440kb, should i use it cuze the most of my customer use the dial up connection

evant
12 Jul 2007, 3:17 AM
Probably not, only take the things you need:

http://extjs.com/download/build

faris
12 Jul 2007, 3:51 AM
thank you sir god pleasd you,
this is my 8th day in work with php and ajax

faris
12 Jul 2007, 3:56 AM
i want create i dialog box which chek box should i choice

tryanDLS
12 Jul 2007, 8:11 AM
Until you understand the object dependencies better, you should use the entire ext-all.js file. Once your app is working, you can consider using the 'Build Your Own' page to build a smaller file - it lists all the dependant files for each widget.