what is wrong in this code?
I have to use this piece of code to save some values in table when page loads. The function to search values is in php. I have to use those values in script. I am trying this way but its not working.
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<script>
$(document).ready(function()
{
var msg_top = new array();
msg_top = "<"+"?php echo searchResults('windows');"+"?"+">";
var url = "msg2_mysql.php"
var request = null;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
request=new XMLHttpRequest();
}
开发者_如何学运维 else
{// code for IE6, IE5
request=new ActiveXObject("Microsoft.XMLHTTP");
}
request.open("POST", url, true);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.setRequestHeader("Connection", "close");
request.onreadystatechange = function(){
if (request.readyState == 4) {
if (request.status == 200) {
alert('POST');
} else {
alert(request.status); //
}
}
}
request.send("msg_top=" + encodeURIComponent(msg_top).replace(/%20/g, '+'));
});
</script>
if (request.readyState == 4) {
if (request.status == 200) {
//alert('POST');
} else {
alert(request.status); // fails here
}}
Should probably be something like:
if (request.readyState == 4) {
if (request.status == 200) {
//alert('POST');
} else {
alert(request.status); // fails here
}
}
}
If you pay proper attention to your indentation, you'll notice you never end the anonymous function you create at:
request.onreadystatechange = function(){
精彩评论