need help in ajax

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
rajsekar2u
Forum Commoner
Posts: 71
Joined: Thu Nov 20, 2008 4:23 am

need help in ajax

Post 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>
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: need help in ajax

Post 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>
rajsekar2u
Forum Commoner
Posts: 71
Joined: Thu Nov 20, 2008 4:23 am

Re: need help in ajax

Post by rajsekar2u »

Thanx a lot....
Post Reply