PING to a Server using JavaScript without AJAX

Hi

Hi

Is possible do a ping to a server and know if the server is online or offline without use AJAX?

I found this code but use AJAX

function pingURL() {
// Getting the URL from the User
var URL = $("#url").val();
var settings = {
// Defining the request configuration
cache: false,
dataType: "jsonp",
crossDomain: true,
url: URL,
method: "GET",
timeout: 5000,
headers: {accept: "application/json", "Access-Control-Allow-Origin": "*",},

// Defines the response to be made
// for certain status codes
statusCode: {
200: function (response) {
document.getElementById("outputDiv").innerHTML="<h3 style='color:green'>Status 200: Page is up!";
},
400: function (response) {
document.getElementById("outputDiv").innerHTML="<h3 style='color:red'>Status 400: Page is down.</h3>";
},
0: function (response) {
document.getElementById("outputDiv").innerHTML="<h3 style='color:red'>Status 0: Page is down.</h3>";
},
},
};
// Sends the request and observes the response
$.ajax(settings).done(function (response) {
console.log(response);
})
.fail(function (response) {
console.log("Error" + response);
});
}

I also other code:

function ping(extServer){
var ImageObject = new Image();
ImageObject.src = "http://"+extServer+";
if(ImageObject.height>0){
alert("Servidor en Linea !");
} else {
alert("Servidor fuera de linea :(");
}

}

Hovever with this last code , the system alway return OffLine


(");

What other option can exist?


3 Replies

KP Kokila Poovendran Syncfusion Team August 14, 2023 04:50 PM UTC

Hi Party tecnico,


Thank you for reaching out to our support team.


We understand your concern about checking the server's status using JavaScript without using AJAX. After reviewing your query, it appears that you're trying to display the server status within a card component.


However, it's important to note that retrieving the server's status typically requires sending a request to the server, and this is commonly achieved through AJAX requests. This is due to the nature of web technologies and security considerations.


If you're looking for a solution to display the server's online/offline status, we recommend using AJAX or other similar methods to send a request to the server and receive a response indicating the status.


Regards,

Kokila Poovendran.



PT party tecnico August 15, 2023 02:46 AM UTC

Hi Kokila Poovendran. I am using the within a card component. in where I only can use code JavaScript. and When I try of run it, This generate this error: VM21:29 Uncaught TypeError: $.ajax is not a function at pingURL (:29:12) at :36:2 How can change this? Regards



KP Kokila Poovendran Syncfusion Team August 16, 2023 12:53 PM UTC

Hi Party tecnico,


We apologize for any inconvenience you've experienced. It seems like there might be a misunderstanding. The Card component primarily functions as a CSS element, used to display values and act as a container.


From your description, it appears that you're encountering an error related to the usage of the $.ajax function in JavaScript. This error can arise when the function is not recognized. To assist you further, we recommend checking out the following resources:


Appuals: https://appuals.com/typeerror-ajax-is-not-a-function-while-using-the-ajax-function/

Stack Overflow: https://stackoverflow.com/questions/18271251/typeerror-ajax-is-not-a-function

Bobby Hadz's Blog: https://bobbyhadz.com/blog/jquery-typeerror-ajax-is-not-a-function

Educativehttps://www.educative.io/answers/error-ajax-is-not-a-function


Loader.
Up arrow icon