views:

137

answers:

2

Dear All,

I have problem in giving ajax functionality to hyperlink, I have Link.html & GetCustomerdata.php. The main function of HTml is send the data to getCutomerData.php and shows flash as "success".

And also I do not want hyperlinking

<a href="#"

instead I need in terms of

<a href=GetCustomer.php?id=<format>

Please anyone help me in this context,Is it possible to clear?

Link.Html

<html>
<head>

<title>Customer Account Information</title>
 <script type="text/javascript">
    var url = "GetCustomerData.php?id="; // The server-side script
   function handleHttpResponse() { 
 if (http.readyState == 4) {
    if(http.status==200) {
    var results=http.responseText;
         document.getElementById('divCustomerInfo').innerHTML = results;
    }
  }
 }
        function requestCustomerInfo() {      
             var sId =10;
             document.getElementById("txtCustomerId").value;
             http.open("GET", url + escape(sId), true);
  http.onreadystatechange = handleHttpResponse;
  http.send(null);
        }   


     function getHTTPObject() {
         var xmlhttp;

           if(window.XMLHttpRequest){
            xmlhttp = new XMLHttpRequest();
       }
       else if (window.ActiveXObject){
             xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            if (!xmlhttp){
                      xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
               }

     }
  return xmlhttp;
}

var http = getHTTPObject();
</script>

</head>

<body>
<a href="getCustomerData.php?id=10&onclick="requestCustomerInfo();return false;">Show Me</a>  
<div id="divCustomerInfo"></div>
</body>
</html>

... and My php file is just flashes theSuceess Message

getCustomerData.php

<?php
echo "Success"
?>
+1  A: 

You placed the anchor onclick event inside the href attribute. onclick should be written as a separate attribute:

...
<a href="getCustomerData.php?id=10" onclick="requestCustomerInfo();return false;">Show Me</a>

To prevent the link from redirecting the page, you need to stop the click event from executing the link default action. Inside your function call:

function requestCustomerInfo(event) {
    if (!event) var event = window.event;
    event.preventDefault();
    ...
}
Eran Galperin
Thanks Eran! It Works Fine
venkatachalam
A: 

you already start the same question http://stackoverflow.com/questions/377854

Ariel