2012-11-06 117 views
-2

这是我的代码。AJAX和PHP不起作用

<html> 
<head> 
<title>Patient Information Management</title> 
<!--showDate AJAX script --> 
<script language="javascript" type="text/javascript"> 
function showDate(){ 
var ajaxRequest; // The variable that makes Ajax possible! 
try{ 
    // Opera 8.0+, Firefox, Safari 
    ajaxRequest = new XMLHttpRequest(); 
}catch (e){ 
// Internet Explorer Browsers 
try{ 
    ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
}catch (e) { 
try{ 
    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); 
    }catch (e){ 
    // Something went wrong 
    alert("Your browser broke!"); 
    return false; 
    } 
} 
} 
// Create a function that will receive data 
// sent from the server and will update 
// div section in the same page. 
ajaxRequest.onreadystatechange = function(){ 
if(ajaxRequest.readyState == 4){ 
    var ajaxDisplay = document.getElementById('ajaxDiv'); 
    ajaxDisplay.value = ajaxRequest.responseText; 
} 
} 
// Now get the value from user and pass it to 
// server script. 
var date = document.getElementByName('Date').value; 
var queryString = "?date=" +date ; 
ajaxRequest.open("GET", "getappointmentdate.php" +queryString, true); 
ajaxRequest.send(null); 
} 
</script> 
<!-- //Calender Script --> 
<link rel="stylesheet" type="text/css" media="all" href="scripts/jsDatePick_ltr.min.css"/> 

<!--JavaScript--> 
<script type="text/javascript" src="scripts/jsDatePick.min.1.3.js"></script> 

<!--For javascript Calendar--> 
<script type="text/javascript"> 
window.onload = function(){ 
    new JsDatePick({ 
     useMode:2, 
     target:"Date", 
     cellColorScheme:"orange", 
     dateFormat:"%d-%m-%Y", 
    }); 

}; 
</script> 
</head> 

<body> 

<div class="wrapper"> 
<?php include("include/header.php"); ?> 
<div class="clear"></div> 
<?php 


<div class="clear"></div> 



</div> <!-- end of sidemenu div --> 
</div> <!-- end of left div --> 

<div id="right" > 

<h2>anything</h2> 
<div class='grey_divider'></div> 

<p>&nbsp;</p> 
<div class='grey_divider'></div> 
<h3>Make Appointment</h3> 
<form action=""> 
Date &nbsp;:&nbsp; <input type="text" size="20" id="Date" name="Date"/> 
<input type='button' onclick='showDate()' value='Submit'/> 
</br> 
</br> 

</form> 


</div> 
</body> 
</div> 
</html> 

当我点击按钮'提交'时,它应该运行PHP文件,但不幸的是,没有任何事情发生,有人可以帮助我。 我抓住HTML日期getElementByName而不是getElementById,因为'id'已被用来抓住日历js。它会影响?

+2

可以查看浏览器控制台,看是否发生了JavaScript错误?如果有,在这里发布将是有用的。 – Ren

+0

不,它没有从浏览器发生任何错误。只是结果返回是空的。 – user1802939

回答

0

我很肯定你需要赶上按钮点击并停止它的默认行为.preventDefault()然后调用你的函数。

添加的代码

$('input[type="submit"]').click(function(e) { 
    e.preventDefault(); 
    showDate(); 
}); 
+1

你可以展示自己的方式吗?我非常感谢。 – user1802939

+0

以上显示在更新 – deiga

+0

@deiga我想你需要提供解决方案在他的味道(javascript)作为后没有任何jQuery相关标签:( – swapnesh