Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何解码返回到角度按钮的json数组单击_Php_Mysql_Angularjs - Fatal编程技术网

Php 如何解码返回到角度按钮的json数组单击

Php 如何解码返回到角度按钮的json数组单击,php,mysql,angularjs,Php,Mysql,Angularjs,我试图获取从mysql查询返回到angular调用的键值对。点击我得到我想要的三行(见下面的结果) HTML: 因为我返回了3行,所以我喜欢将名称分配给表单中的第一个名称、第二个名称和第三个名称字段 谢谢对我来说,一切看起来都很好(除了你奇怪的命名约定)。现在可以在视图中使用数据 <form> <div ng-repeat="n in names tracked by $index"> <h3>{{$index + 1}}. Name:

我试图获取从mysql查询返回到angular调用的键值对。点击我得到我想要的三行(见下面的结果)

HTML:

因为我返回了3行,所以我喜欢将名称分配给表单中的第一个名称、第二个名称和第三个名称字段


谢谢

对我来说,一切看起来都很好(除了你奇怪的命名约定)。现在可以在视图中使用数据

<form>
    <div ng-repeat="n in names tracked by $index">
        <h3>{{$index + 1}}. Name:</h3>
        Firstname: <input ng-model="n.Name" /><br />
        Secondname: <input ng-model="n.City" /><br />
        Lastname: <input ng-model="n.Country" /><br />
        <button type="button" ng-click="submitOne(n)">Save this</button>
    </div>
    <button type="button" ng-click="submitAll(names)">Save all</button>
</form>
顺便说一句,你不应该使用内容类型:未定义。 使用:

此外,您正在执行POST请求,这很好,但是您使用“params”向请求中添加数据。您应该使用“data”键,因为“params”将添加GET参数

params–{Object.}–字符串或对象的映射 将使用paramSerializer序列化并作为GET追加 参数

数据–{string | Object}–作为请求发送的数据 消息数据


在我看来,一切都很好(除了你奇怪的命名约定)。现在可以在视图中使用数据

<form>
    <div ng-repeat="n in names tracked by $index">
        <h3>{{$index + 1}}. Name:</h3>
        Firstname: <input ng-model="n.Name" /><br />
        Secondname: <input ng-model="n.City" /><br />
        Lastname: <input ng-model="n.Country" /><br />
        <button type="button" ng-click="submitOne(n)">Save this</button>
    </div>
    <button type="button" ng-click="submitAll(names)">Save all</button>
</form>
顺便说一句,你不应该使用内容类型:未定义。 使用:

此外,您正在执行POST请求,这很好,但是您使用“params”向请求中添加数据。您应该使用“data”键,因为“params”将添加GET参数

params–{Object.}–字符串或对象的映射 将使用paramSerializer序列化并作为GET追加 参数

数据–{string | Object}–作为请求发送的数据 消息数据


您的视图中有emp_no、first_name、last_name,但数据中有name、City Country-您想做什么?我喜欢将first的行名称指定给first name。第二行名称返回变量第二行名称。。你能改进一下你的样品吗?我的意思是视图模型变量不同于数据模型变量,也不同于视图中的标签。您的模型键是Name、City、Country,但值是Firstname、SecondName、ThirdName?让我试试这个示例。如何在postdate函数中分解scope.name,以便只将第2行这样的特定行发布到html

demo

value1

value2

value3

提交
我更新了答案(请参见“submitOne(n)”与“submitAll(name)”。只需将这些函数添加到控制器范围变量中,并对数据执行任何操作。您的视图中有emp_no、first_name、last_name,但数据中有name、City Country-您想做什么?我想将第一行的名称指定给first name。第二行的名称返回变量Second name..等等,您可以尝试改进吗您的示例?我的意思是视图模型变量不同于数据模型变量,也不同于视图中的标签。您的模型键是Name、City、Country,但值是Firstname、SecondName、ThirdName?让我试试这个示例。如何在postdate函数中分解scope.Name,以便只发布某一行,如将第2行添加到html

demo

value1

value2

value3

提交
我更新了我的答案(请参见“提交人(n)”与“提交人(姓名)”的比较)。只需将这些函数添加到控制器范围变量中,然后对数据执行任何操作。感谢它帮助我理解。感谢它帮助我理解
<form>
    <div ng-repeat="n in names tracked by $index">
        <h3>{{$index + 1}}. Name:</h3>
        Firstname: <input ng-model="n.Name" /><br />
        Secondname: <input ng-model="n.City" /><br />
        Lastname: <input ng-model="n.Country" /><br />
        <button type="button" ng-click="submitOne(n)">Save this</button>
    </div>
    <button type="button" ng-click="submitAll(names)">Save all</button>
</form>
// add this to your server script (example: php), before you output the data
header('Content-Type: application/json; charset=utf-8');
Content-Type: 'application/x-www-form-urlencoded; charset=utf-8'