jQuery return links are not working. I have Used jQuery and the basic Ajax feature. My jQuery returns the links from file Links_ajax.php.
I giving the code samples.
GetCustomerData.php has:
<html> <script type='text/javascript'> <script src='ajax.js' type='text/javascript'> $(function() { ..... $.ajax({ type: 'POST', url: 'Links_ajax.php', data: 'category='+category , success: function(data){ $('#response').html(data); } }); } ...... } ... <! Links return here <div id='response'> </div> </html> <? echo 'Some Code'; ?> ....
My Links_ajax.php has the following code
.... echo '<a href='getCustomerData.php?id=10' onclick='requestCustomerInfo();return false;'>show me </a>'; echo '<a href='getCustomerData.php?id=11' onclick='requestCustomerInfo();return false;'>show me </a>'; ....
Now I come to the Main Page getCustomerData.php. I have used the Ajax feature that returns link from Links_ajax.php.
.....
So, my ajax.js has the following Ajax scripts.
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(event) { if(event &&event.preventDefault) event.preventDefault(); else if (window.event && window.event.returnValue) window.eventReturnValue = false; var sId = 10; 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(); // We create the HTTP object
……
Now I come to the problem. When I execute the GetCustomerdata.php, I am able to get all the links from ajax.JQuery. And upon clicking that, I need a basic Ajax feature since loading the same <div> </div>. But I am unable to view it even though I done. Is there anything wrong in my code? Or do I have to use any other feature?
First i wonder why you write a custom function HTTPrequest while you already have jquery object, infact you already use $.ajax at the top but then create getHTTPObject() later.
The problem is the javascript function requestCustomerInfo() never delegate to handle the link at the ajax response data, you need to delegate the function as a callback of the ajax request