Page 1 of 1

need help in ajax

Posted: Wed Jun 17, 2009 7:09 am
by rajsekar2u
Hi,

Am using an ajax function in bottom of my webpage to display the details of a select name.
when i click on the link, the page is moving to the top. the following is the script i used.

Ajax Function:

Code: Select all

function Todisplaydescription(val)
{
    //alert(stuid);
    var httpxml;
    try
        {
          // Firefox, Opera 8.0+, Safari
          httpxml=new XMLHttpRequest();
         }
    catch (e)
    {
    // Internet Explorer
          try
                    {
                 httpxml=new ActiveXObject("Msxml2.XMLHTTP");
                    }
            catch (e)
                    {
                try
            {
            httpxml=new ActiveXObject("Microsoft.XMLHTTP");
             }
                catch (e)
            {
            alert("Your browser does not support AJAX!");
            return false;
            }
            }
    }
    function stateck() 
    {
        if(httpxml.readyState==4)
        {
            document.getElementById("description").innerHTML=httpxml.responseText;
         }
    }
    var url="pagename.php";
    url=url+"?val="+val;
    httpxml.onreadystatechange=stateck;
    httpxml.open("GET",url,true);
    httpxml.send(null);
}
</script>
The div id, where the to value display:

Code: Select all

 
<a href="#" onclick="Todisplaydescription('somevalue')" >Example </a>
<div id="description"></div>

Re: need help in ajax

Posted: Wed Jun 17, 2009 11:33 am
by kaszu
You must stop click event. Change

Code: Select all

<a href="#" onclick="Todisplaydescription('somevalue')" >Example </a>
into

Code: Select all

<a href="#" onclick="Todisplaydescription('somevalue'); return false;" >Example </a>

Re: need help in ajax

Posted: Thu Jun 18, 2009 12:36 am
by rajsekar2u
Thanx a lot....