首页 \ 问答 \ Angular - 将HTTP发布数据发送到服务器[HOW TO](Angular - send HTTP post data to server [HOW TO])

Angular - 将HTTP发布数据发送到服务器[HOW TO](Angular - send HTTP post data to server [HOW TO])

我正在尝试使用POST方法将数据从我的登录FORM发送到PHP后端写入。

我的Angular代码如下:

$scope.getToken = function(){
    // console.log $scope.login to make sure I'm not sending empty data
    console.log($scope.login);
    $http({
        method: 'POST',
        url: '../../api/v1/Oauth.php',
        data: { 'login' : $scope.login, 'password' : $scope.password }
    }).then(function successCallback(response) {
        console.log(response);
    }, function errorCallback(response) {
       console.log(response);
    });
};

然后我尝试在我的PHP上捕获它:

if((isset($_POST['login']) AND isset($_POST['password'])))
{
    $username = $_POST['login'];
    $password = $_POST['password'];
    echo $username;
}
else
    var_dump($_POST);

此语句始终转到else并返回空数组。 有人可以告诉我我做错了什么或者如何调试这个? 因为它看起来我正确地从角度发送数据但它没有来到服务器。

谢谢亲切的问候Andurit


I'm trying to send data from my login FORM to backend writen in PHP using POST method.

my Angular code looks like:

$scope.getToken = function(){
    // console.log $scope.login to make sure I'm not sending empty data
    console.log($scope.login);
    $http({
        method: 'POST',
        url: '../../api/v1/Oauth.php',
        data: { 'login' : $scope.login, 'password' : $scope.password }
    }).then(function successCallback(response) {
        console.log(response);
    }, function errorCallback(response) {
       console.log(response);
    });
};

and after that I try to catch it on my PHP:

if((isset($_POST['login']) AND isset($_POST['password'])))
{
    $username = $_POST['login'];
    $password = $_POST['password'];
    echo $username;
}
else
    var_dump($_POST);

This statement always go to else and return empty array. Can someone advise me what I'm doing wrong or how can I debug this? Because it looks that I send data fron angular correctly but it didn't come to server.

Thanks Kind Regards Andurit


原文:https://stackoverflow.com/questions/34182857
更新时间:2023-04-19 09:04

最满意答案

对于字符串,数组,指向数组的指针或切片a,主表达式

a [低:高]

构造子串或切片。 索引表达式低和高选择哪些元素出现在结果中。 结果索引从0开始,长度等于high - low。

对于数组或字符串,索引低和高必须满足0 <=低<=高<=长度; 对于切片,上限是容量而不是长度。

索引

表单的主要表达

斧头]

表示由x索引的数组,切片,字符串或映射的元素。 值x分别称为索引或映射键。 以下规则适用:

对于类型A或* A,其中A是数组类型,或者对于类型S,其中S是切片类型:

x must be an integer value and 0 <= x < len(a)

a[x] is the array element at index x and the type of a[x] is
the element type of A

if a is nil or if the index x is out of range, a run-time panic occurs

制作切片,地图和频道

make(T, n)       slice      slice of type T with length n and capacity n
make(T, n, m)    slice      slice of type T with length n and capacity m

y必须是整数值且0 <= y <len(pixel [] uint8)。 x必须是整数值且0 <= x <len(pixel [] [] uint8)。 例如,

package main

import "tour/pic"

func Pic(dx, dy int) [][]uint8 {
    pixels := make([][]uint8, dy)
    for y := 0; y < dy; y++ {
        pixels[y] = make([]uint8, dx)
        for x := 0; x < dx; x++ {
            pixels[y][x] = uint8(x * y)
        }
    }
    return pixels
}

func main() {
    pic.Show(Pic)
}

Slices

For a string, array, pointer to array, or slice a, the primary expression

a[low : high]

constructs a substring or slice. The index expressions low and high select which elements appear in the result. The result has indexes starting at 0 and length equal to high - low.

For arrays or strings, the indexes low and high must satisfy 0 <= low <= high <= length; for slices, the upper bound is the capacity rather than the length.

Indexes

A primary expression of the form

a[x]

denotes the element of the array, slice, string or map a indexed by x. The value x is called the index or map key, respectively. The following rules apply:

For a of type A or *A where A is an array type, or for a of type S where S is a slice type:

x must be an integer value and 0 <= x < len(a)

a[x] is the array element at index x and the type of a[x] is
the element type of A

if a is nil or if the index x is out of range, a run-time panic occurs

Making slices, maps and channels

make(T, n)       slice      slice of type T with length n and capacity n
make(T, n, m)    slice      slice of type T with length n and capacity m

y must be an integer value and 0 <= y < len(pixel[]uint8). x must be an integer value and 0 <= x < len(pixel[][]uint8). For example,

package main

import "tour/pic"

func Pic(dx, dy int) [][]uint8 {
    pixels := make([][]uint8, dy)
    for y := 0; y < dy; y++ {
        pixels[y] = make([]uint8, dx)
        for x := 0; x < dx; x++ {
            pixels[y][x] = uint8(x * y)
        }
    }
    return pixels
}

func main() {
    pic.Show(Pic)
}

相关问答

更多
  • 在Go没有其他办法。 是的,我同意这是冗长但必要的。 第二个make()语句完全独立于第一个。 可以认为,编译器应该能够从pic[i]推断出类型,但是现在还没有。 另一点:如果在第二种情况下省略了类型,make()语句将如何看? make()仍然需要做实际的分配,并能够指定所需的len /容量。 作为一个附注,你混合了片长度。 练习说明顶级切片应该有长度dy ,而不是dx因为你放入代码。 There is no other way to do this in Go. Yes, I agree it is v ...
  • 首先,请不要写porownanie == True 。 porownanie本身就是一个布尔值,所以只有porownanie就足够了 问题是while a[i+r]==b[j+r] and porownanie == True: . Python从左到右计算表达式,所以当porownanie为False ,它应该退出循环,但是它会在a[i+r]==b[j+r]之前从它退出循环之前得到错误! 修复很简单:只需切换订单即可 while porownanie and a[i+r]==b[j+r]: 顺便说一句,这 ...
  • 那么,你点击每个链接,打印它,然后回去? 这非常低效。 您可以使用.get_attribute方法快速获取页面上所有链接的URL。 links = [i.get_attribute('href') for i in driver.find_elements_by_xpath('.//a')] for i in links: print i 将打印页面上所有链接的列表。 要选择较小的页面区域,请找到要从中选择的“框架”元素,然后使用 frame.find_elements_by_xpath('//a ...
  • #15 : 我猜int的允许比常量更少的位? 对,就是这样。 根据规范, “数字常量表示任意精度的值并且不会溢出” ,而类型int具有32位或64位 。 #21 : 提到哪种语言? 没有; 它暗指着#16 ,它用相同的词语for表达同样的东西 - 关于环路。 #25 : a type declaration does what you'd expect的有点不幸,我同意(因为它假设读者可能期望太多...),但它意味着你正在定义一个结构(与struct关键字)并绑定输入名称“顶点”给它, type Verte ...
  • 解释Python的切片符号是SO答案。 引用格雷格的话: “如果项目的数量少于你的要求,Python对程序员很友好。例如,如果你要求[: - 2]并且只包含一个元素,那么你会得到一个空列表而不是错误。有时你会更喜欢这个错误,所以你必须意识到这可能会发生。“ Explain Python's slice notation is the SO answer. To quote Greg: "Python is kind to the programmer if there are fewer items tha ...
  • 我看到了几个问题: 在page.cshtml的标记中page.cshtml为page.cshtml步( #step-four )指定的元素 第五步没有定义element ,我认为除非你将orphan选项设置为true否则需要一个element 您必须在page.cshtml包含所有游览代码,如果您在page.html检查演示的来源,则最后引用的脚本index.js包含游览实例。 最后,我不确定这是否有任何区别,但我认为你对tour.restart();调用tour.restart(); 和tour.star ...
  • PreparedStatement stmt = getCon().prepareStatement("SELECT * FROM MesLib.tblSchoolRecordsr where strstudName = ? and strDoubleCheckCode = ? and (lngstudID NOT LIKE '-[^0-9]') "); stmt.setString(1, studName); stmt.setString(2, Double ...
  • 片 对于字符串,数组,指向数组的指针或切片a,主表达式 a [低:高] 构造子串或切片。 索引表达式低和高选择哪些元素出现在结果中。 结果索引从0开始,长度等于high - low。 对于数组或字符串,索引低和高必须满足0 <=低<=高<=长度; 对于切片,上限是容量而不是长度。 索引 表单的主要表达 斧头] 表示由x索引的数组,切片,字符串或映射的元素。 值x分别称为索引或映射键。 以下规则适用: 对于类型A或* A,其中A是数组类型,或者对于类型S,其中S是切片类型: x must be an inte ...
  • 这是一个实现细节。 在这一行 fmt.Println("In two days.", today + 2) today属于time.Weekday类型,其中int为其底层类型, 2为无类型整数常量,将转换为time.Weekday并将执行添加。 fmt.Println()的实现将检查传递给它的值是否实现fmt.Stringer ,并且因为time.Weekday ,它的String()方法将被调用,其实现是: // String returns the English name of the day (" ...
  • 我是否需要创建一个for循环,将我的切片的每个元素都分配给dx范围内的一个值? 是: 一个外部循环,为[x]分配一个dx大小的[]uint8切片, 为每个元素a[x] (这是一个[]uint8 )的内部循环' y ',以便为a[x][y]分配所请求的值(即,像x^y这样的“有趣函数”之一x^y , (x+y)/2和x*y )。 x和y是切片范围内的索引( a ,然后a[x] ):请参阅“ For statements ”。 我喜欢(x ^ y) * (x ^ y) : 正如rwilson04评论如下 : x ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)