我想将一个值传递给ajax函数。这在表单中很简单并且按预期工作(在下面的示例中将id更改为gal_id1),但是我的定位器传递的值出现未定义的错误。将值通过锚点传递给ajax。
function ajax_post(){
// Create our XMLHttpRequest object
var hr = new XMLHttpRequest();
// Create some variables we need to send to our PHP file
var url = "ajax_json_gallerySQL.php";
var gid = document.getElementById("gal_id").value;
var vars = "gal_id="+gid;
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(vars); // Actually execute the request
document.getElementById("status").innerHTML = "processing...";
}
Test Pictures.
THis is working
$myValue='13';
This is not working
echo "
![Image](images/Parents/Brook/Brook1.jpg)
";
?>