Javascript 在React Native上使用Ajax

Javascript 在React Native上使用Ajax,javascript,python,ajax,react-native,Javascript,Python,Ajax,React Native,我正在研究react native with javascript,在这里我想执行一个python脚本。我想在其中使用以下代码: return $.ajax({ type: 'GET', url: 'test.py', success: function(response) { console.log(response); }, error: function(response) { return console.error(

我正在研究react native with javascript,在这里我想执行一个python脚本。我想在其中使用以下代码:

  return $.ajax({
    type: 'GET',
    url: 'test.py',

    success: function(response) {
      console.log(response);
    },
    error: function(response) {
      return console.error(response);
    }
  });
但我得到的错误是代码无法访问。由于某些原因,react native无法使用ajax。您知道我如何在react native中正确使用ajax吗?

我建议您使用或获取


您的示例基于Jquery,我不认为React-Native使用Jquery。

您不能在React-Native中使用Jquery。Jquery需要处理HTML/CSS DOM,但react native有自己的DOM实现。这是一个本地应用程序

您可以使用Axios或fetch。在fetch中,您需要自己处理错误代码。我建议你使用

您可以使用fetchapi。当您在代码块之前返回时,通常会收到“代码无法访问”警告。
axios.get(url)
      .then(function (response) {
        console.log(response.data)
      })
      .catch(function (error) {
        if (error.response) // error from server
          console.log(error.response.data.message)
        else
          console.log("Error Occured. Please try Again.!") // error from app side
      });
  })
}