这是我的ajax函数
<script language="JavaScript" type="text/javascript">
var num = 1;
function ajax_post(){
// Create our XMLHttpRequest object
var hr = new XMLHttpRequest();
// Create some variables we need to send to our PHP file
var url = "javas.php";
hr.open("POST", url, true);
// Set content type header information for sending url encoded variables in the request
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// Access the onreadystatechange event for the XMLHttpRequest object
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
}
}
// Send the data to PHP now... and wait for response to update the status div
hr.send("num=" + (++num)); // Actually execute the request
document.getElementById("status").innerHTML = "processing...";
}
现在我也找到了正确的 div/类来运行 ajax 函数:
$('.eventcontainer.button').click(function() {
$.post('javas.php', function(data) {
$(this).parent('div').find('.status').html(data);
})
});
但是我不确定在我的代码中在哪里实现它
最佳答案
如果您想在多个浏览器上运行您的代码,那么编写您自己的 ajax 请求并不是一个好主意。如果您手头有 jQuery 并且想要发布 ajax 请求,请使用 jQuery 函数:
$.post('ajax/test.html', function(data) {
$('.result').html(data);
});
关于php - Document.ready() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8517947/