React-Native - 获取发布请求失败(Android)

时间:2018-03-25 17:51:16

标签: javascript php react-native

我有这个PHP:

<?php

  include('connect.php');

  $data = json_decode(file_get_contents('php://input'), true);
  $statement = $pdo->prepare("SELECT * FROM M_Messages where M_B_Id = " . $data->blogId);
  $statement->execute();
  $Messages = $statement->fetchAll(PDO::FETCH_ASSOC);


  $statement = $pdo->prepare("SELECT * FROM B_Blogs where B_Id = " . $data->blogId);
  $statement->execute();
  $Blog = $statement->fetchAll(PDO::FETCH_ASSOC);

  echo json_encode(array("Messages" => $Messages, "Blog" => $Blog));
?>

这是我的提取调用React-Native:

var formData = {
        'blogId': this.state.blogId
    };

   fetch('http://www.bloggaa.co.uk/getMessagesByBlogId.php', {
          method: 'POST',
          headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
          },
          body: JSON.stringify(formData)
        })
        .then((response) => response.json())
        .then((responseJson) => {

            //alert(responseJson.Messages);
            //this.setState({
                //dataSource:this.state.ds.cloneWithRows(responseJson.Messages),
                //blogTitle: responseJson.Blog[0].B_Title,
            //  });


      })
      .catch((error) => {
        alert('ddddd ' + error.message);
      });

我在网址输入: http://xxxxxx.co.uk/getMessagesByBlogId.PHP?blogId=1

但我得到了回复: {&#34;消息&#34;:[],&#34;博客&#34;:[]}

并且React-Native返回JSON解析错误无法识别的令牌&#39;&lt;&#39;

我设法得到了“GET&#39;请求工作,但没有运气Post方法。

有人可以帮忙吗?

0 个答案:

没有答案