Angularjs $ http POST请求空数组 [英] Angularjs $http POST request empty array

查看:116
本文介绍了Angularjs $ http POST请求空数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下 $ http请求成功执行,但另一端的PHP脚本收到空 $ _ POST 它应该接收'test'和'testval'的数组。任何想法?

The following $http request executes successfully, yet the PHP script on the other end receives an empty $_POST array when it should receive 'test' and 'testval.' Any ideas?

$http({
    url: 'backend.php',
    method: "POST",
    data: {'test': 'testval'},
    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    }).success(function (data, status, headers, config) {
    console.log(data);

    }).error(function (data, status, headers, config) {});


推荐答案

如果您想发送这些简单数据,请尝试这个:

If you wan to send just that simple data, try this:

$http({
    url: 'backend.php',
    method: "POST",
    data: 'test=' + testval,
    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    }).success(function (data, status, headers, config) {
        console.log(data);

    }).error(function (data, status, headers, config) {});

和php部分应该是这样的:

And php part shoul be like this:

<?php
    $data = $_POST['test'];
    $echo $data;
?>

这对我有用。

这篇关于Angularjs $ http POST请求空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆