Javascript 如何将ajax文章连接到PHP文件中的特定条件?
因此,我在使用AJAX的html文件中编写了一个名为onclick的函数,但我想让本文转到mysql中的一个特定表Javascript 如何将ajax文章连接到PHP文件中的特定条件?,javascript,php,jquery,mysql,ajax,Javascript,Php,Jquery,Mysql,Ajax,因此,我在使用AJAX的html文件中编写了一个名为onclick的函数,但我想让本文转到mysql中的一个特定表 $('#submitIFC').click(function(e) { var request; if (window.XMLHttpRequest) { request = new XMLHttpRequest(); } else { request = new ActiveXObject("Microsoft.XMLHTTP"); } var o
$('#submitIFC').click(function(e) {
var request;
if (window.XMLHttpRequest) {
request = new XMLHttpRequest();
} else {
request = new ActiveXObject("Microsoft.XMLHTTP");
}
var opinionIFC = $('ul.sort').sortable('toArray').join(',');
request.onreadystatechange = function() {
if ((request.readyState===4) &&(request.status===200)) {
var return_data = request.responseText;
document.getElementById('rank_ul').innerHTML= 'return_data';
// Preventing the default action triggered by clicking on the link
e.preventDefault();
e.preventDefault();
}//end of if
}//end of onreadystatechange function
//send requested movie to php file which will send to the external server
request.open("POST", "results.php", true);
request.send(opinionIFC);
document.getElementById('rank_ul').innerHTML='<img src="ajax-loader.gif">';
}
为什么ajax post请求没有过滤到我的php文件中
非常感谢您,非常感谢您的帮助。如果您没有发送opinionIFC参数,请尝试:
request.send('opinionIFC=' + opinionIFC);
您还需要设置内容类型
request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
您使用的是jquery,为什么要滚动自己的ajax代码?所有readystate垃圾都可以用一个$.ajax()
替换。并且您的php代码容易受到攻击。
request.setRequestHeader("Content-type","application/x-www-form-urlencoded");