Can some one tell me how to pass variable Yto $('a:eq(0)').click()? I need to alert the server respond to the .click() function. I am using a PHP framework if that’s important.
<script>
$(document).ready(function() {
function clockIn(str){
if (window.XMLHttpRequest)
{ // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("message").innerHTML=xmlhttp.responseText;
var y = xmlhttp.responseText ;
}
}
xmlhttp.open("GET","http://localhost/gasstation/index.php/welcome/check_time_clock/"+ str,true);
xmlhttp.send();
}
$( "input:submit, a", ".login" ).button();
$("a:eq(0)").click(function(){
clockIn(<?php echo $emp_id; ?>);
});
$("a:eq(1)").click(function(){
alert('m') ;
})
});
</script>
Since you are making an ajax call you have to wait until the server responds so you cannot get the value of
yinsideclickhanlder. You can pass a handler toclockInand then execute it once the ajax response comes. Try this.Since you are using jQuery you should leverage it completly to make your code simple and clean. Instead of creating write the code your own to create
xmlhttprequest object and bla bla you can smply use$.ajaxof jQuery for the same use. Your code will become like this.