亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

發布到數據庫不起作用(錯誤/警告:JSON 輸入意外結束)

發布到數據庫不起作用(錯誤/警告:JSON 輸入意外結束)

PHP
翻閱古今 2022-10-09 17:15:28
我正在使用 React Native 開發移動應用程序。問題是我似乎無法將任何內容插入數據庫。我有一個注冊頁面,用戶需要在其中編寫用戶名和密碼(并重復該密碼),幾個月前該頁面運行良好。我沒有更改該特定頁面上的任何內容,但是當我開始添加新頁面時,例如另一個不起作用的頁面,它停止工作并給了我可以在此處看到的警告:另一個不起作用的頁面是用戶可以在其中發布帶有標題日期等的工作。此頁面尚未完成,但應該已完成,以便用戶可以將某些內容發布到數據庫,但它給了我可以在此處看到的錯誤:注冊頁面的代碼如下(不包括樣式表):import React, { Component } from "react"; import { View, Text, StyleSheet, Alert, TextInput, ImageBackground, Image, AsyncStorage, TouchableOpacity } from "react-native";import { Button, Icon, withTheme } from 'react-native-elements';const SIGNUP_URL = 'http://kamilla-server.000webhostapp.com/app/signUp.php';class SignUp extends Component { constructor(props) {    super(props);    this.state= {        email: '',        password: '',        password2: '',    }; }async onSignUp() {    const { email, password, password2 } = this.state;    if(this.state.email != '' && this.state.password != '' && this.state.password2 != '') {        if(password != password2) {            Alert.alert('Password matcher ikke', 'De to indtastede passwords skal v?re det samme password')        } else {            const response = await fetch(SIGNUP_URL, {                headers: {                    Accept: 'application/json',                    'Content-Type': 'application/json'                },                method: 'POST',                body: JSON.stringify({ email, password }),            })            const data = await response.json()            if (data.error) {                alert(data.error)            } else {                AsyncStorage.setItem('UserID', data.user.UserID)                this.props.navigation.navigate('SignUpMessage')            }        }    } else {        Alert.alert('Tomme felter', 'Venligt indtast email og password for at kunne oprette en bruger')    }}
查看完整描述

2 回答

?
楊魅力

TA貢獻1811條經驗 獲得超6個贊

問題是這一行: $_SESSION['userID'] = $getUser['UserID']; The $getUserneeds to be $getNewUser,因為這是我從中獲取的變量的名稱。我一定是在不知不覺中改變了它,從而產生了問題。



查看完整回答
反對 回復 2022-10-09
?
回首憶惘然

TA貢獻1847條經驗 獲得超11個贊

我在這里可能錯了,但我最好的猜測是您的 fetch api 收到錯誤,您應該嘗試將async onSignUp函數的 fetch 修改為:


  await fetch(SIGNUP_URL, {<params>})

    .then(res => {

      // Handle API Errors

      if (!res.ok) {

        console.log(res.statusText);

      }

      // Return if no errors

      return res.json();

    })

    // this is the data you want

    .then(data => data)

    // it will only reject on network failure or if anything prevented the request from completing

    .catch(error => {

      console.log(error.message)

    });

您可以嘗試上述方法,看看您是否在響應中收到錯誤!希望這可以幫助!!


查看完整回答
反對 回復 2022-10-09
  • 2 回答
  • 0 關注
  • 179 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號