I´m trying to learn ajax, sitting here sinse 3 hours and trying to understand what I need to make it run.
I´m using it on Scriptly with Xampp.
This is my code:
<head>
<title>Titel</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Ajax Example!</title>
<script src="js\jquery/jquery.js"></script>
<script>
$(document).ready(function(){
$("#btnSubmit").click(function(){
//alert("hello");
$.ajax({
type: "POST",
url: "http://localhost/inde.php",
data: {
myName: "durgesh technoclass"
},
success: function(output){
alert(output);
}
});
});
});
</script>
</head>
<body>
<form>
<button id="btnSubmit">Click me !</button>
</form>
I even watched a tutorial on Youtube and copied all the code from there. The rating of the tutorial is good, the code seems to work for him, but why doesn´t it work for me ?! I don´t understand that.
The Jquery works, but ajax doesn´t. The Script just reloads the page and displays nothing.
Please help.
Edit:
May it be that it doesn´t work, because xampp doesn´t run an actual server ?
On request, here´s the code of the "inde.php"
:
<?php
echo "Welcome from Server";
?>
Edit 2: Solution: I messed up the path of the inde.php. Just fixed it.
It works but there´s a mistake in the code. It had been fixed by Tanvir Ahmad Sohan. You can find his fix in his answer down there.