I am struggling to make a simple ajax request. I have no idea why it doesn't work.
<script> function checkdata() { var reqdata = "aha"; alert(reqdata); $.ajax({ type: "POST", url: "https://example.com/cs/test.php", data: reqdata, cache: false, success: function(returnedata) { alert(returnedata); } }); //end of ajax return true; } </script>
<input type="button" value="CheckData" onclick="checkdata();">
The file https://example.com/cs/test.php has one: echo "done"; which works properly. When I navigate to the page with the browser I see just "Done"
What is the problem here? Thanks.
Don't forget to include https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js
your code will not work without this
here is something that worked ,, change your function declaration to match this
checkdata = function () {
var reqdata = "aha";
....
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.