PDA

View Full Version : How to make a sync request by using Extjs 3.0



kandy0619_China
29 Jan 2010, 1:26 AM
I have search the forum,but i can't find a way to resolve my problem!
Someone said that edit extj source, but i can't find the Ext.lib.Ajax.request function.
Can it in ext source?
Please help me ,
I'm a chinese ,and i love Extjs.
My english is poor, but i can't find any solution in baidu.com,so i am here!

jbo87
29 Jan 2010, 1:32 AM
Whats a sync request? Just another HTTP method like GET, POST, PUT and DELETE?

If so:


Ext.Ajax.request({
url: 'service.php',
method: 'SYNC',
success: ...
});


BTW: Editing the Ext JS source is a bad idea. Use Ext.override for example!

kandy0619_China
29 Jan 2010, 1:36 AM
Whats a sync request? Just another HTTP method like GET, POST, PUT and DELETE?

If so:


Ext.Ajax.request({
url: 'service.php',
method: 'SYNC',
success: ...
});


BTW: Editing the Ext JS source is a bad idea. Use Ext.override for example!


method is just "post" \ "Get" . "SYNC"??? What?

jbo87
29 Jan 2010, 1:38 AM
I do not understand you.

kandy0619_China
29 Jan 2010, 1:40 AM
Whats a sync request? Just another HTTP method like GET, POST, PUT and DELETE?

If so:


Ext.Ajax.request({
url: 'service.php',
method: 'SYNC',
success: ...
});


BTW: Editing the Ext JS source is a bad idea. Use Ext.override for example!

i know, override is a well way. But now how to make sync?
i found a solution ,but i use XMLHttpRequest.


var response;
if (window.ActiveXObject) {
response = new ActiveXObject('Microsoft.XMLHTTP');
} else if (window.XMLHttpRequest) {
response = new XMLHttpRequest();
}
response.open('POST', URL, false);
response.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
response.send("menuId="+menuId);

kandy0619_China
29 Jan 2010, 1:42 AM
Like this,


Ext.Ajax.request( {
url : URL,
sync : true,
params : {menuId : menuId},
method : 'post',
success : function(response, options) {
var array = Ext.util.JSON.decode(response.responseText);
if (array.isMaintain == "1") {
isMaintain = true;
}
if(array.isExport == "1"){
isExport = true;
}
if(array.isAudit == "1"){
isAudit = true;
}
}
});



i want to make this request sync.

jbo87
29 Jan 2010, 1:47 AM
Ext.Ajax.request({
url: URL,
method: 'POST',
headers: {
'Content-type': 'application/x-www-form-urlencoded'
},
params: {
menuId: menuId
},
success: function (response, options) { /* handle response here */ }
});


Edit: I think i got you. But Ajax is always async... no other way!

kandy0619_China
29 Jan 2010, 2:01 AM
Ext.Ajax.request({
url: URL,
method: 'POST',
headers: {
'Content-type': 'application/x-www-form-urlencoded'
},
params: {
menuId: menuId
},
success: function (response, options) { /* handle response here */ }
});


Edit: I think i got you. But Ajax is always async... no other way!


no other way? :(( but i'm using the XMLHttpRequest in the successful resolution of my question.

jbo87
29 Jan 2010, 3:00 AM
I think you just assume the request to be done before the next command is interpreted. That is not the case in general. Insert a sleep() statement into your webservice and test your code again.

kandy0619_China
29 Jan 2010, 4:41 AM
I think you just assume the request to be done before the next command is interpreted. That is not the case in general. Insert a sleep() statement into your webservice and test your code again.


Actually, the function what i need is :

when customer click the menu, Ext.Ajax must send a request to the server, util the reponse has return , the page must not be init() . That's why i want to make the request sync..

i don't know if you can understand what i need?

jbo87
29 Jan 2010, 5:01 AM
success: function () {init()}

kandy0619_China
29 Jan 2010, 5:18 AM
success: function () {init()}


Yes, This way was which i have used before!
But the codes are in the Ext.onReady(function(){ .....codes.......});
How can i use it where request has success?
success:function(){
Ext.onReady()????
}
if there has a quote to Ext.onReady()???

jbo87
29 Jan 2010, 5:42 AM
move the code that gets executed by Ext.onReady callback into the success callback of your Ext.Ajax.request

kandy0619_China
29 Jan 2010, 5:55 AM
move the code that gets executed by Ext.onReady callback into the success callback of your Ext.Ajax.request


Thank you very much ! i think i know how to do it ! Thanks again!