How to send ajax request to a localhost? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to send ajax request to a localhost?

I am in mobile.

11th Sep 2020, 1:14 PM
Sameer Crestha
Sameer Crestha - avatar
6 Answers
+ 3
$(document).ready(function() { $("button").click(function() { var myData = { "name": "aName", "pasw": "aPasw" }; $.ajax ({ url: "myURL", type: "POST", data: myData }).done(function(data) { outputJSON = JSON.stringify(data); console.log(outputJSON); output = JSON.parse(outputJSON); console.log(output.Result); }).fail(function(data, err) { alert("fail " + JSON.stringify(err)); }); }); });
11th Sep 2020, 1:31 PM
JaScript
JaScript - avatar
+ 4
Using the fetch API https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch Kindly visit all the links and study them carefully. The server side can be written in any language of your choice. Or you can practice with JSON placeholder API if you don't want to create a back end. https://jsonplaceholder.typicode.com/
11th Sep 2020, 4:17 PM
Ore
Ore - avatar
+ 2
The url is you webside, which will receive the request and manage it for example: http://localhost:port/myside.php A number of port will be only needed, if your setted port is other than 80.
11th Sep 2020, 3:02 PM
JaScript
JaScript - avatar
+ 2
And the myside.php should be in the htdocs directory.
11th Sep 2020, 3:35 PM
JaScript
JaScript - avatar
+ 1
Example of url plz
11th Sep 2020, 2:10 PM
Sameer Crestha
Sameer Crestha - avatar
+ 1
11th Sep 2020, 3:07 PM
JaScript
JaScript - avatar