Yii2 ActiveController 支持的所有url类型

1. 列表 get

wx.request({
      url: 'http://localhost:8080/articles',
      header: {
        'Content-Type':'application/json'
      },
      method: 'GET',
      success:function(res) {
        console.log(res.data)
      }
    })
 

2. 单个 get

wx.request({
      url: 'http://localhost:8080/articles/1',
      header: {
        'Content-Type':'application/json'
      },
      method: 'GET',
      success:function(res) {
        console.log(res.data)
      }
    })

3.新增create post

wx.request({
      url: 'http://localhost:8080/articles',
      header: {
        'Content-Type': 'application/json'
      },
      method: 'POST',
      data: {
        title: "test article",
        content: "test cotent",
        category_id: 1,
        status: 10
      },
      success: function (res) {
        console.log(res.data)
      }
    })

4. 更新, PUT

wx.request({
      url: 'http://localhost:8080/articles/8',
      header: {
        'Content-Type': 'application/json'
      },
      method: 'PUT',
      data: {
        title: "modified title",
        content: "modified content",
        category_id: 1,
        status: 10
      },
      success: function (res) {
        console.log(res.data)
      }
    })

5. 删除 DELETE

wx.request({
      url: 'http://localhost:8080/articles/9',
      header: {
        'Content-Type': 'application/json'
      },
      method: 'DELETE',
      data: {
      },
      success: function (res) {
        console.log(res.data)
      }
    })

6. OPTIONS

wx.request({
      url: 'http://localhost:8080/articles/1',
      header: {
        'Content-Type': 'application/json'
      },
      method: 'OPTIONS',
      data: {
      },
      success: function (res) {
        console.log(res)
      }
    })
 

http://www.codeblogbt.com/archives/62134

 

猜你喜欢

转载自blog.csdn.net/fox64194167/article/details/80288994
今日推荐