raise.js:
window.onload=init;
function init(){
var submit=document.getElementById("submit");
submit.onclick=sub;
}
function sub(){
var url="raise.php";
var title=document.getElementById("title");//title of a question
var content=document.getElementById("inputContent");//content of a question
var checktype=document.getElementsByName("type");
var type;//type of a question
if(checktype[0].checked){
type="java";
}
else if(checktype[1].checked){
type="c++";
}
else{
type="html";
}
var point=document.getElementsByTagName("select");
var reward=point[0].value;//reward point
url=url+"?title="+title.value;
url=url+"?content="+content.value;
url=url+"?type="+type;
url=url+"?reward="+reward;
var xmlhttp;
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
alert("asde");
}
}
xmlhttp.open("GET",url,true);
xmlhttp.setRequestHeader("Content-Type","utf-8");
xmlhttp.send();
}
raise.php:
<?php
echo "<script>alert('123')</script>";
$title=$_GET['title'];
$content=$_GET['content'];
$reward=$_GET['reward'];
$type=$_GET['type'];
?>
that confuses me alert('123') is not executed but alert("asde") is ,I want to know why..and am I right while trying to retrieve these data with php...I'm not very familiar with ajax...please show me some codes based on my data..thank you very much..