How can I make XHR.onreadystatechange return its result?

后端 未结 3 2209
無奈伤痛
無奈伤痛 2020-12-14 03:16

I\'m new to JavaScript programming. I\'m now working on my Google Chrome Extension. This is the code that doesn\'t work... :P

I want getURLInfo function

3条回答
  •  忘掉有多难
    2020-12-14 03:42

    For small edit talking about post: https://stackoverflow.com/a/5362513/4766489

    ...
    if (typeof callback == "function") {
         //var resp  = xhr.responseText;
         var resp  = JSON.parse(xhr.responseText);
         callback(resp);
    }
    ...
    

    And when you call

    ...
    function(data) {
        alert(data);
        /* now do something with resp */
    }
    ...
    

提交回复
热议问题