Pergunta

I have Javascript file where I m trying to make a AJAX call and supposed to get JSON data.

  $.ajax({
        type: "POST",
        url: "er.js", // this is the same file
        data: {
            action: 'analyzePost',
            c: c,
            title: title,
            content: content,
            audience: audience
        },
        dataType: "json",
  "success": function(result) {
     console.log("OK: ", result);
     r = result;
   },
   "error": function(result) {
     console.error("!!!!!!ERROR!!!!!!!!!:", result);
   },
   "async": false
    });

I have a function in same file that look like this.

function showAnalyzePost(c, title, content, audience){
    return analyzePost(c, $("#oauth_token").val(), $("#oauth_token_secret").val(), title, content, audience);
}

I did worked with AJAX before but that involved PHP as well. In this case there is no server side script. Maybe I have to create .json file or maybe use getJson but I am not sure how to do that.

Problem: AJAX is not even being triggered. It does not throw error nor return good result.

Please ask question if I did not explain this properly. Can someone guide me here... Thanks

Foi útil?

Solução

AJAX is for client-server interaction. If you are staying on the client side, just call your js function with the appropriate values for parameters.

var r = analyzePost(c, title, content, audience);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top