Hi I'm using ajax for posting the data in to database, I'm using php as server background for posting the data in mysql database, for
Ex: $name = $_POST['name'];
$query = "INSERT INTO table('name') VALUES ('".$name."');
$result = mysql_query($query)
when the user click on the submit button, i just made a onlick function of ajax post_data(), so what i need is i want the value in 开发者_如何学Cthe textbox so that i can pass it to ajax, how to get the value of the textbox
var url = "get_data.php";
var params = "name=?"; (how to get the name enter in the text box)
http.open("POST", url, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);
You can give the textbox and id.
And then using this code
var textValue = document.getElementById("textboxid").value;
you can get as well set the value in the textbox.
You shouldn't send $POST vars directly to the db. Look up sanitization.
var url = "get_data.php";
var validValue=validate(document.getElementById('textboxid').value) ;
var params = "name=?"+validValue;
http.open("POST", url, true);
<!-- assuming your text box is-->
<input type =textbox id="textboxid">
And don't forget to sanitize at the server side too.
var params = "name=?"; (how to get the name enter in the text box)
you can try:
var params = "name="+document.getElementById('theTextBoxId').value;
精彩评论