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
最满意答案
对于字符串,数组,指向数组的指针或切片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) }
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.
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) }
相关问答
更多-
切片切片类型(Slice of slices types)[2022-05-20]
在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 ... -
指数超出范围(index out of range in while)[2022-12-02]
首先,请不要写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 ...
-
Bootstrap Tour - 如何从目的地页面返回?(Bootstrap Tour - How do I return back from destination page?)[2024-01-21]
我看到了几个问题: 在page.cshtml的标记中page.cshtml为page.cshtml步( #step-four )指定的元素 第五步没有定义element ,我认为除非你将orphan选项设置为true否则需要一个element 您必须在page.cshtml包含所有游览代码,如果您在page.html检查演示的来源,则最后引用的脚本index.js包含游览实例。 最后,我不确定这是否有任何区别,但我认为你对tour.restart();调用tour.restart(); 和tour.star ... -
指数3超出范围(Index of 3 is out of range)[2022-01-16]
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 ...