If you want to send ajax request using yahoo user interface library, for that follow the below mentioned code step by step.
First Import Yahoo libraries in page you want to access them
- Include namespace echo (reference path)
YAHOO.namespace("echo");
Calling a function in script
YAHOO.echo.addField.field_lookup(this)
here addField refers to the prototype class and field_lookup refers to the function which is called on the following event.
- field_lookup function and ajax request handling
YAHOO.echo.addField = {
field_lookup: function(s){
// Callback for ajax request
var callback = {
success: function(o){
//When ajax request successful do the job
YAHOO.echo.refreshPanel(o.responseText);
},
failure: function(o){
//When ajax request failure do some job
alert('Unable to connect to server.');
},
cache: false
}
//URL for ajax request
var url = 'mypage.php?_fn=View&id=' + s.getAttribute("data");
//Send ajax request
YAHOO.util.Connect.asyncRequest('GET', url, callback);
}
};
//Ajax request success function
YAHOO.echo.refreshPanel = function(contents){
// Use the response code
alert(contents);
}
0 Comment(s)