在 GET 请求中添加多个参数

Adding more than one param in GET request

本文关键字:参数 添加 GET 请求      更新时间:2023-09-26
url: "../api/api.php? fxn:" + encodeURIComponent(getCatergories) & "jsn"= +encodeURIComponent{"code":"1"},

var app = angular.module('MyTutorialApp',[]);
app.controller("MainController", function($scope,$http){
    $scope.loadpeople= function()
    {
       $http
     .get({
        url: "../api/api.php",
        data:{
            fxn:getCategories,
            jsn:'{"code":"1"}'
        }
    })
    .success(function(data){
        console.log("SUCCESS");
        $scope.people = data;
    })
    }
});

这是网址,我需要在参数后附加网址。 我知道怎么做一个,你能告诉我两个参数怎么做吗?

澄清:这个问题被大量修改和更改,不会更新我的答案以反映到"新"问题。

最简单易读的方法是分配data参数:

url: 'the URL',
data: {
    a: 'something',
    b: 'something else'
},
...

数据:

要发送到服务器的数据。如果还不是字符串,则会将其转换为查询字符串。它被附加到 GET 请求的 url 中

阿贾克斯文档

但是要回答您的问题,只需将&放在字符串中并修复查询字符串:

url: "../api/api.php?fxn=" + encodeURIComponent(getCatergories) +
                   "&jsn=" + encodeURIComponent('something')