mousecoder mousecoder - 4 months ago 18
Ajax Question

jQuery get changing the URL parameter itself

I am making a get request using jquery to the local server in Flask. Here is the endpoint in Flask

@app.route('/getNews', methods=['GET', 'POST'])
def getNews():
return jsonify(news['news'])


Here is the call from HTML

$.get({
url:"http://0.0.0.0:9090/getNews",
success: function(data){
console.log(data);
news = data;
},
data:"d",
dataType: "json"
});


Something annoying and very strange is happening. It keeps on giving me this error:

jquery-1.11.0.min.js:4 GET http://0.0.0.0:9090/[object%20Object] 404 (NOT FOUND)


I have no clue why is it changing the address by itself. Any idea?

Answer

Your url argument is a string, not in the data object. The second argument is the data you are passing to the endpoint. The third argument is the success handler. And the last argument is the datatype expected back.

$.get( "http://0.0.0.0:9090/getNews", 'd', function( data ) {
      console.log(data);
      news = data;
    }, "json");