405(方法不允许)Angular 4代码点火器

时间:2017-10-26 12:28:25

标签: php angular codeigniter

我想向我的api发出请求但是我收到以下错误:

  

1.OPTIONS http://localhost/restserver/book/add_book.php 405(方法不允许)

     
      
  1. 无法加载http://localhost/restserver/book/add_book.php:预检的响应包含无效的HTTP状态码405
  2.   

这是我的控制器(CI)

//create book into database
function add_book_post()
{
    //store all parameter in array dataBook
    $dataBook = array(
        'title' => $this->post('title'),
        'author' => $this->post('author'),
        'isbn' =>$this->post('isbn')            
    );

    //call method tambah_museum() in model m_book with array dataBook
    $insert = $this->m_book->create_book($dataBook);

    //if tambah_museum() success
    if($insert) {
        $output['status'] = true;
        $output['message'] = 'success';
        $output['last_row'] = $insert;
    } else {
        $output['status'] = false;
        $output['message'] = 'failed';
    }

    //send response
    $this->response($output);
}

这是我的组件

import { BookService } from './../book.service';
import { Component, OnInit } from '@angular/core';
import { Book } from "../book";


@Component({
  selector: 'app-book',
  templateUrl: './book.component.html',
  styleUrls: ['./book.component.css']
})
export class BookComponent implements OnInit {

  constructor(public bookService: BookService ) { }
  books:any;

  ngOnInit() {
    this.getBooks();
  }

  deleteBook(id){
    this.bookService.deleteBook(id)
    .subscribe(() =>{
     this.getBooks();
   })
 }

}

这是我的观点

<div class="container-fluid">
<div class="row">
  <div class="card col-md-7">
      <div class="card-body">
        <table class="table table-responsive table-striped">

          <thead>
              <tr>

                <th scope="col">Title</th>
                <th scope="col">Author</th>
                <th scope="col">ISBN</th>
                <th width="325">Actions</th>
              </tr>
            </thead>
            <tbody>
              <tr *ngFor="let book of books" >

                <td>{{book.title}}</td>
                <td>{{book.author}}</td>
                <td>{{book.isbn}}</td>
                <td>
                  <button class="btn btn-primary "> Detail </button>
                  <button class="btn btn-success " [routerLink]="['/book-edit']"> Edit </button>
                  <button class="btn btn-danger" (click)="deleteBook(book.id)"> Delete </button>                
              </td>
            </tr>           
          </tbody>
        </table>       
    </div>  
  </div>  

我的控制器(CI)或前端是否有任何问题?

0 个答案:

没有答案