I have a message page written in jsf and in this page i have a table containing message titles as commandlink. In these commandlinks i have nested ajax to request to my bean to read the message content from db and show it on the page. I tested this functionality by showing the message content in a textearea. But the problem is here that i want to show the content in a javascript alert. So whenever I click the commandlink an alert shows the content of the message. But if I define the javascript method as commandlink onclick attribute then it would run before ajax request and nothing would be shown! I think we need an attribute that defines a javascript method that would run after ajax request completion. But what's that attribute ? thanx for any useful answer !
Asked
Active
Viewed 790 times
0
-
RTFM: http://api.jquery.com/jquery.ajax/ "success" option. – Marc B Jan 19 '14 at 08:43
-
please give me the exact code sample – hamid Jan 19 '14 at 08:44
-
You say you've got functionality to show the message in a textarea. showing it in an alert should be an utterly trivial change. – Marc B Jan 19 '14 at 08:45
-
I am looking for that attribute doing this : do a javascript function after ajax request completion in jsf. – hamid Jan 19 '14 at 08:58
-
@MarcB: where did the OP said that he's using jQuery? Shouldn't you RTFQ? – BalusC Jan 19 '14 at 16:46
2 Answers
0
new to XMLHttpRequest? try play around with this code
<!DOCTYPE HTML>
<html>
<head><title></title></head>
<body>
<input type="button" id="foo" value="load url" /><br/>
<input type="text" id="url" /><br/>
<textarea id="responses"></textarea>
<script type="text/javascript">
document.querySelector("#foo").addEventListener("click",function(ev){
var xhr=new XMLHttpRequest();
var url=document.querySelector("#url").value;
xhr.open("GET",url);
xhr.addEventListener("readystatechange",function(ev){
var xhr=ev.target;
if(xhr.readyState<4)return;
document.querySelector("#responses").value+=xhr.responseText;
alert(xhr.responseText);
});
xhr.send();
});
</script>
</body></html>

hanshenrik
- 19,904
- 4
- 43
- 89
0
XHTML
<h:commandLink id="button" value="button">
<f:ajax render="@this"
onevent="openPopup"
listener="#{myBean.getData}" />
</h:commandLink>
Javascript
function openPopup(data){
if(data.status == "success"){
// open popup with your message
}
}

StarsSky
- 6,721
- 6
- 38
- 63