dongxiezhi0590 2019-02-19 21:45
浏览 123

在离子3和MySQL中POST http:// localhost:8100 / api.php / 404(未找到)

My app is trying to POST to http://localhost:8100/api.php/, but I am encountering a 404 (Not Found) error.

myregst.html

 <ion-list>

    <ion-item>
        <ion-input type="text" placeholder="اسم المستخدم حقيقى" [(ngModel)]="user_name"></ion-input>
      </ion-item>        <ion-item>
          <ion-input type="text" placeholder="رقم هاتف ملك لك " [(ngModel)]="user_phone"></ion-input>
        </ion-item>        <ion-item>
            <ion-input type="password" placeholder="الرقم السري" [(ngModel)]="user_password"></ion-input>
          </ion-item>

    <ion-item>
      <ion-label> اختر المحافظة</ion-label>
      <ion-select  interface="action-sheet"  [(ngModel)]=" user_zone">
        <ion-option   value="GIZA" > GIZA </ion-option>
      </ion-select>
    </ion-item>
    <ion-item>
      <ion-label> اختر المدينة</ion-label>
      <ion-select  interface="action-sheet" [(ngModel)]=" user_city">
        <ion-option   value="DOQI" > DOQI </ion-option>
      </ion-select>
    </ion-item>
    <ion-item>
      <div padding>
        <button ion-button color="primary" block (click)="lognew()" > تسجيل  </button>

      </div>

    </ion-item>

  </ion-list>

myregst.ts

    lognew(){
    if(this.user_name==""){
      const toast = this.toastCtrl.create({
        message: 'يرجى ادخال الاسم صحيح',
        duration: 3000
      });
      toast.present();
    }else if(this.user_phone==""){
      const toast = this.toastCtrl.create({
        message: 'يرجى ادخال رقم  هاتفك',
        duration: 3000
      });
      toast.present();
    }else if(this.user_password==""){
      const toast = this.toastCtrl.create({
        message: 'يرجى كتابة الرقم السري',
        duration: 3000
      });
      toast.present();
    }else if(this. user_zone==""){
      const toast = this.toastCtrl.create({
        message: 'يرجى اختيار المحافظة ',
        duration: 3000
      });
      toast.present();
    }else if(this. user_city==""){
      const toast = this.toastCtrl.create({
        message: 'يرجى اختيار  المنطقة',
        duration: 3000
      });
      toast.present();
    }else{

      let body ={
        user_zone: this.user_zone,
        user_city: this.user_city,
        user_phone: this.user_phone,
        user_name: this.user_name,
        user_password: this.user_password,
        akis:'add'
      };
      this.ConPro.usernew(body,'api.php/').subscribe( data => {
         var alartpesan = data.msg;
        if(data.success){
          this.navCtrl.pop();
          const toast = this.toastCtrl.create({
            message: 'add succesful',
            duration: 3000
          });
          toast.present();

        }else{
          const toast = this.toastCtrl.create({
            message: alartpesan,
            duration: 3000
          });
          toast.present();
        }

      });

    }
}

providers.ts

 import { HttpClient } from '@angular/common/http';
import { Http , Headers,RequestOptions } from '@angular/http';

 import { Injectable } from '@angular/core';
 import 'rxjs/add/operator/map';
/*
Generated class for the RecipesProvider provider.

  See https://angular.io/guide/dependency-injection for more info on 
 providers
and Angular DI.
*/
@Injectable()
export class RecipesProvider {
 ask: string


 constructor(public HttpClient: HttpClient ,public Http: Http ) {

   this.ask = "http://localhost/blueapp/"

 }

  usernew(body:any, file:any) {
  let type = "application/json; charset=UTF-8";
  let headers = new Headers({ 'Content-Type': type });
  let options = new RequestOptions({ headers: headers });
  return this.Http.post(this.ask=file,JSON.stringify(body),options).map(res => res.json());

}

}

db.php

<?php
$db = new mysqli("localhost","root","","tabkh");
$db->query("set names utf8");

api.php

<?php
include ("db.php");
 header("Access-Control-Allow-Origin: *");
 header("Access-Control-Allow-Credentials: true");
 header("Access-Control-Allow-Methods: POST,GET,OPTIONS");
 header('Access-Control-Allow-Headers: Content-Type,Authorization, X- 
 Requested- 
  With');
   header("Content-Type: application/json; charse=utf-8");



$postjson = json_decode(file_get_contents('php://input'), true);
if($postjson['akis'] == 'add'){`
 $password = md5($postjson['password']);
 $query =( "INSERT INTO user SET 
        user_zone = '$postjson[user_zone]',
        user_city = '$postjson[user_city]',
        user_phone = '$postjson[user_phone]',
        user_name = '$postjson[user_name]',
        user_password=' $postjson[user_password]',
        echo $postjson[user_zone];
 ");
  if($query) $result = json_encode(array('success'=>true));
else $result = json_encode(array('success'=>false ,'msg' => 'error ,plase 
 tru agin' ));
echo  $result;
};

Image of the error

Error displayed

  • 写回答

1条回答 默认 最新

  • dtef9322 2019-02-19 21:52
    关注

    The problem is the trailing slash in your URL:

    this.ConPro.usernew(body,'api.php/')
    

    It should be :

    this.ConPro.usernew(body,'api.php')
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度