user1032465
user1032465

Reputation: 117

jQuery ajax only works locally but not on Server

my front-end sends a jquery-ajax request to a back-end in order get values to calculate something. This works fine on my local webserver but if i do it online, i only get result 0 in my calculations, which means that i dont get the ajax response.

Here is my ajax-method:

function transmitToBackend(weights, subfeatures) {
    $.post("../Backend/StartFeasibilityAnalysis.php", {
        features: JSON.stringify(weights), 
        subfeatures: JSON.stringify(subfeatures)
    }, function(data){
        convertData(data);
    });
}

Could it be that the convertData(data) Method gets called before the data was transmitted from the back-end?

Best regards

Upvotes: 1

Views: 1514

Answers (3)

Swaraj Giri
Swaraj Giri

Reputation: 4037

Could it be that the convertData(data) Method gets called before the data was transmitted from the back-end?

Nope, the callback is only executed after a successful response is received.

As for not working on the server, check if you can ping the url or use dev tools to check the http response code.

Upvotes: 1

B. Kemmer
B. Kemmer

Reputation: 1537

You gotta check your Console first. If it can't find the resource (404 HTTP Response Code), there is something wrong with your URL.
You can definitely use relative Paths with an ajax call.
I only wonder why do you start with 2 dots?
If you don't get a 404 try to use your method like this:

function transmitToBackend(weights, subfeatures) {
    $.post("/Backend/StartFeasibilityAnalysis.php", {
        features: JSON.stringify(weights), 
        subfeatures: JSON.stringify(subfeatures)
    }, function(data){
        convertData(data);
    });
}  

Upvotes: 1

Viswanath Polaki
Viswanath Polaki

Reputation: 1402

Try like this

function transmitToBackend(weights, subfeatures) {
$.post("{yourdomain/ip}/Backend/StartFeasibilityAnalysis.php", {
    features: JSON.stringify(weights), 
    subfeatures: JSON.stringify(subfeatures)
}, function(data){
    convertData(data);
});
}

Upvotes: 0

Related Questions