tmonteit
asked on
Prototype Library Question
I have a JS prototype function that calls a servlet looking for the value in a key-value pair.
GetValue: function(key){
debugAPI("GetValue: " + key);
var myAjax = new Ajax.Request(
'/TRIAD/api.do?dispatch=ge tValue&key =' + key,
{
method: 'get',
onComplete: function(response) {$F("result") = response.responseText;}
});
}, ...
The servlet puts the value in a 'request.setAttribute("val ue", value); ' method.
How do I get that value back into a Javascript variable as the return value for the function?
as in:
var myValue = getValue(key);
GetValue: function(key){
debugAPI("GetValue: " + key);
var myAjax = new Ajax.Request(
'/TRIAD/api.do?dispatch=ge
{
method: 'get',
onComplete: function(response) {$F("result") = response.responseText;}
});
}, ...
The servlet puts the value in a 'request.setAttribute("val
How do I get that value back into a Javascript variable as the return value for the function?
as in:
var myValue = getValue(key);
Hi,
Try looking into these functions...
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.X MLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function sndReq(action) {
http.open('get', 'rpc.php?action='+action);
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();
if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById(up date[0]).i nnerHTML = update[1];
}
}
}
R.K
Try looking into these functions...
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.X
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function sndReq(action) {
http.open('get', 'rpc.php?action='+action);
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();
if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById(up
}
}
}
R.K
ASKER
Moroclaven,
So far, your example makes the most sense. Still confusing is at the end state you have the variable within an embeded function 'showResponse'.
I want to make the variable the return value of clickMe.
How do I pass it from the embeded function to the clickMe function so it can be returned?
Thanx...
So far, your example makes the most sense. Still confusing is at the end state you have the variable within an embeded function 'showResponse'.
I want to make the variable the return value of clickMe.
How do I pass it from the embeded function to the clickMe function so it can be returned?
Thanx...
ASKER
The key to this question is "RETURN VALUE".
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Note this solution was exactly on target.
https://www.experts-exchange.com/questions/22062473/Need-Syncronous-AJAX-Call.html
Moroclaven's answer here seems to work. It is a good example on how to use XMLHttp.
As an example:
http://72.34.47.183/~irlazy/ajax.html
<script src="prototype-1.4.0.js"><
<script>
function clickMe() {
var myAjax = new Ajax.Request( 'test.html', { method: 'get', onComplete: showResponse });
}
function showResponse(originalReque
alert(originalRequest.resp
}
</script>
<input type=button value="Click Me" onClick=clickMe()>
The text that is returned by test.html is displayed in the alert box.