Fetch vs. AjaxCall

前端 未结 2 949
说谎
说谎 2021-01-29 23:50

What is the difference between typical AJAX and Fetch API?

Consider this scenario:

function ajaxCall(url) {
  return new Promise(function(resolve, reject         


        
2条回答
  •  闹比i
    闹比i (楼主)
    2021-01-30 00:05

    Your ajaxCall is returning the responseText from the XMLHttpRequest object. It is filtering it out.

    You need to read the response Text in the fetch code.

    fetch('/foo/').then(x => x.text()).then(console.log)
    

    You can also use x.json() or x.blob()

提交回复
热议问题