1

My problem is when I call some function than render in a definite div, not send my request. This is my function.

<script type="text/javascript">
//<![CDATA[
function ajaxFunction() {
var xmlHttp;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
return xmlHttp;
} catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
return xmlHttp;
} catch (e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;
} catch (e) {
alert("Tu navegador no soporta AJAX!");
return false;
}}}
}


function CargarDatos(_pagina,capa) {

var ajax;
ajax = ajaxFunction();
ajax.open("POST", _pagina, true);
ajax.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
ajax.onreadystatechange = function()
{

if (ajax.readyState==1){
document.getElementById(capa).innerHTML = " Aguarde por favor...";
}


if (ajax.readyState == 4)
{
document.getElementById(capa).innerHTML =
ajax.responseText;


}}
ajax.send();

}

And this is the line where I call this function

<li><h:commandLink  action="#{personal.cargarEvento}" onclick="CargarDatos('pages/Politica/nacional/inicio.html','content'); " value="Nacional" >

If I use this line the render works

<li><h:commandLink  action="#{personal.cargarEvento}" onclick="mojarra.jsfcljs (CargarDatos('pages/Politica/nacional/inicio.html','content')); " value="Nacional" >

But generate a JavaScript error and not call my Bean.

The target is when I click some element render other page in a div and simultaneously execute some method in one bean.

What is wrong?

How can I make it work?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Java Developer
  • 172
  • 1
  • 2
  • 10
  • You're mixing some concepts which causes that the code makes no sense (you can't perform both a synchronous *and* an asynchronous request in 1 click; note that this is not a JSF limitation, it's just basic HTML/JS). Please clarify the concrete functional requirement so that it can be better understood. Why exactly do you need to invoke the action method? What exactly is it doing? Why exactly do you need to send an ajax request from outside JSF on? Why not just using a JSF targeted ajax tag such as JSF 2.x's `` or in case of JSF 1.x a component library such as Ajax4jsf? – BalusC Nov 07 '12 at 18:53
  • @BalusC Thx, well I Understand your point of view, in this sentence "ajax.open("POST", _pagina, true);", the parameter true mean is async, but implicity the commandlink invoke two request in one thread. Basically this function Load one page on a div of my principal page. That is I need to do. – Java Developer Nov 07 '12 at 20:53

0 Answers0