In fact im working on a small php script ! I have recently added some feature anyway i still have an issue which is : In html file i have put textarea and an submit input I want that when the user click on it the infos of textarea will be sent to a php file without refreshing the page ! Thank you.
Asked
Active
Viewed 458 times
-1
-
[Using ajax to send form data to php](http://stackoverflow.com/questions/18869908/)? – Mr. Polywhirl Jan 06 '14 at 11:32
-
I dont want to use jquery – user3027295 Jan 06 '14 at 11:34
-
try with this pure JavaScript code http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first – yashhy Jan 06 '14 at 11:39
-
I want to post data not to show a div @Yashhy – user3027295 Jan 06 '14 at 11:58
-
yeah @user3027295 it was just a example I gave you, see this it would be usefull http://stackoverflow.com/a/9713078/1778834 – yashhy Jan 06 '14 at 12:00
1 Answers
0
Then you should have a look at ajax:
http://api.jquery.com/jquery.ajax/
$("#mysubmitbutton").click(function() {
$.ajax({
url: "mywebsite.com/save-comment.php",
type: "post",
data: {commentText: $("#comment").val()},
success: function(text) {
if(text == "true") {
alert("It worked! Your data were saved hurrayyy!");
}
},
error: function() {
alert("Print some error here!");
}
});
});
On serverside accept your data:
$myText = $_POST["commentText"];
$query = "UPDATE comment SET text = '" . mysql_real_escape_string($myText) . "'";
if(mysql_query($query) == true) {
echo "true";
} else {
echo "false";
}
die();

Steini
- 2,753
- 15
- 24
-
-
Well then google for an example script for "javascript ajax" and use that instead, the serverside stuff is basically the same but you gonna have a hard time if jquery is too hard for you, belive me... Besides, what is the point? JQuery is easy to use, slim and takes care of any browser compatiblity problems for you because it works as a general abstraction layer of JavaScript, But your choice then... – Steini Jan 06 '14 at 11:39
-