Tuesday, October 2, 2012

Calling Ajax Function in Struts Running Example

function AjaxFunction()
{
    var xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    }
    var url="userwelcome.do?method=getContactById&contact_id="+cntId;
    xmlHttp.onreadystatechange=function()
    {
        if (xmlHttp.readyState==4)
        {
            var content=xmlHttp.responseText;
            document.getElementById("Res_Div_ID").innerHTML=    xmlHttp.responseText;
            document.getElementById("Div_ID").style.display        =    "none";
            document.getElementById("Disp_Div_ID").style.display=    "none";
        }
    };
    xmlHttp.open("POST",url,true);
    xmlHttp.send(null);
}

function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

No comments:

Post a Comment

How ChatGPT can Benefit Coding: Your Guide to Leveraging an AI Language Model

 Introduction: Hello, coders! Welcome to this blog post on how ChatGPT, an AI language model, can benefit your coding skills and projects. A...