Morgan Allen Morgan Allen - 2 months ago 16
Ajax Question

Printing server response in an AJAX callback (using jquery)

I have control over my server endpoint

@app.route('/predict', methods=['GET', 'POST', 'OPTIONS'])
@crossdomain(origin='*')

def predict():
return 'predict12'


I want to return
predict12
in the callback of my AJAX call.

$.ajax({
type: "POST",
url: 'https://linear-yen-140912.appspot.com/predict',
data: 'data',
success: function test(){console.log()},
});


What should I put in the
success
function so it prints
predict12
?

Answer
$.ajax({
type: "POST",
url: 'https://linear-yen-140912.appspot.com/predict',
data: 'data',
success: function test(result){console.log(result)},
});

the success has the result of the AJAX call, and thats what you should be using