解析JSON对象 - Angularjs + PHP(Parsing JSON Object - Angularjs + PHP)
我正在为一个与服务器上的PHP API通信的Angular应用程序进行一些CRUD操作。 我是PHP的新手,所以当我想删除数据库中的条目时,我很难解析我发送到delete.php的内容。 当我在请求的数据属性中发送记录的id时,它会带来带有值的名称,因此Data包含'id = 1'。
在PHP结束时,我发现了一个使用$ _Post ['id']来获取删除条件的示例,但是我可以告诉它不起作用,因为我发送的文件不是' t匹配该名称。 我知道有一些方法可以编码为JSON或以其他方式获取PHP端的值,但我尝试了它,无论我做了什么,它删除整个表而不是我想指定的条目..!
我应该如何收集数据并对其进行解析以使其适合delete()函数?
在App.js中:
$http({ method: 'POST', url: 'http://localhost:8080/sns/delete.php', data: {id: user.id} }).success(function(response){ if(response.status == 'OK'){ var index = $scope.users.indexOf(user); $scope.users.splice(index,1); } });
delete.php:
<?php include 'DB.php'; $db = new DB(); $tblName = 'members'; if(!empty($_POST['id'])){ $condition = $_POST['id']; $delete = $db->delete($tblName,$condition); if($delete){ $data['status'] = 'OK'; $data['msg'] = 'User data has been deleted successfully.'; }else{ $data['status'] = 'ERR'; $data['msg'] = 'Some problem occurred, please try again.'; } }else{ $data['status'] = 'ERR'; $data['msg'] = 'POST id was, please try again.'; } echo json_encode($data); exit;
I'm working on some CRUD operations for an Angular app that communicates with a PHP API on the server. I'm very new to PHP so I'm have trouble parsing what I send to the delete.php when I want to delete an entry in the database. When I send the record's id in the Data properties of the request it brings the name with the value, so Data contains 'id=1', for example.
On the PHP end I went off an example that used $_Post['id'] to get the condition for doing the deleting but from what I can tell that doesn't work because of the fact I'm sending a file that doesn't match that name. I know there are ways to encode to JSON or otherwise get the value on the PHP end but I tried it and whatever mess I made of it it deletes the entire table rather than the entry I want to specify..!
How should I go about collecting the data and parsing it so that it can fit into the delete() function?
In the App.js:
$http({ method: 'POST', url: 'http://localhost:8080/sns/delete.php', data: {id: user.id} }).success(function(response){ if(response.status == 'OK'){ var index = $scope.users.indexOf(user); $scope.users.splice(index,1); } });
delete.php:
<?php include 'DB.php'; $db = new DB(); $tblName = 'members'; if(!empty($_POST['id'])){ $condition = $_POST['id']; $delete = $db->delete($tblName,$condition); if($delete){ $data['status'] = 'OK'; $data['msg'] = 'User data has been deleted successfully.'; }else{ $data['status'] = 'ERR'; $data['msg'] = 'Some problem occurred, please try again.'; } }else{ $data['status'] = 'ERR'; $data['msg'] = 'POST id was, please try again.'; } echo json_encode($data); exit;
原文:https://stackoverflow.com/questions/43815392
最满意答案
我认为你需要清理Subversion凭证存储:
Linux和OSX上的〜/ .subversion / auth
Windows上的USER_HOME \ Application Data \ Subversion \ auth \ svn.simple目录您可能还想阅读有关更改凭据的优秀文章:
在Windows上更改subclipse凭据
在Linux / OSX上更改subclipse凭据 [在1.7(用户名和密码)下]I think you need to clean the Subversion credentials storage:
~/.subversion/auth on Linux and OSX
USER_HOME\Application Data\Subversion\auth\svn.simple directory on WindowsYou may also want to read the excellent article on changing credentials here:
Changing subclipse credentials on Windows
Changing subclipse credentials on Linux/OSX [Under 1.7 (Usernames and Passwords)]
相关问答
更多-
窗口 - >显示视图 - >其他... - > SVN存储库 列出可用的存储库并让您删除不再需要的存储库。 Window -> show view -> Other... -> SVN repositories lists the available repositories and lets you delete the one you don't want any more.
-
Subclipse svn:ignore(Subclipse svn:ignore)[2024-03-26]
您不能svn:忽略已经提交到存储库的文件。 所以你必须: 从存储库中删除文件。 将您的项目(工作副本)更新到头版本。 在Eclipse中重新创建文件。 通过Team-> Add to svn:ignore设置svn:忽略文件。 重新启动日食以反映变化。 祝你好运! You can't svn:ignore a file that is already commited to repository. So you must: Delete the file from the repository. Updat ... -
要为整个项目获得此功能,请在文件资源管理器中打开项目的根目录。 右键单击 - >属性 - > Subversion选项卡 - >属性... - >新建 选择svn:needs-lock 递归地检查应用属性 点击确定 现在subclipse强制你在编辑文件之前获得锁定。 To get this functionality for your entire project open up the root directory of your project in your file explorer. Right ...
-
该端口是Subversion服务器URL的一部分。 如果您需要在Subclipse中更改服务器的URL,那么使用Relocate选项的方法就是这样。 这必须遍历链接到该服务器的所有工作副本并运行svn relocate API,以便工作副本指向新的服务器URL。 您没有提到您正在使用的操作系统,或者您使用的是SVNKit还是JavaHL。 这很重要,因为它还将决定SSH的管理方式。 Eclipse可能已挂起,因为正在生成命令行SSH工具,并且没有终端可以提供它想要提供的提示的答案。 如果您使用的是OpenS ...
-
Eclipse的SVN插件 - Subclipse与Subversive SVN plugins for Eclipse - Subclipse vs. Subversive
-
问题出在客户端,现阶段没有联系服务器。 您的本地存储库检出可能已被您使用的另一个svn客户端静默升级。 或者它也可能被损坏,Subclipse错误地将其报告为它不理解的升级。 如果您不想升级Subclipse,您唯一的方法是从服务器进行新的结账,并从此升级的存储库中复制您的更改。 The problem is with the client side, server is not contacted at this stage. Your local repository checkout might ha ...
-
通常,当您在源和目标分支目录上同时发生更改(添加/删除/修改)时,会发生树冲突。 如果你想简单地忽略这些由主干上的某些东西引起的冲突,而这些冲突你还没有准备好吸收到你的分支中 - 那么它就相当简单了。你可以在冲突的目录(在你的分支工作区)运行“svn resolve” - 然后分支工作区会让你再次提交。 有关详细信息,请参阅此处: http : //svnbook.red-bean.com/nightly/en/svn.ref.svn.c.resolve.html (我认为在某些较旧的版本(如1.4.4)中 ...
-
我认为你需要清理Subversion凭证存储: Linux和OSX上的〜/ .subversion / auth Windows上的USER_HOME \ Application Data \ Subversion \ auth \ svn.simple目录 您可能还想阅读有关更改凭据的优秀文章: 在Windows上更改subclipse凭据 在Linux / OSX上更改subclipse凭据 [在1.7(用户名和密码)下] I think you need to clean the Subversion ...
-
Subclipse中的JavaHL错误(JavaHL Error in Subclipse)[2023-02-07]
无论出于何种原因,看起来SVNKit 1.7.x API(仍处于测试阶段)并不认为该文件夹是工作副本。 我无法确切地说它是对还是错,或者为什么,但这就是API抛出的错误。 他们最近发布了beta2。 您可以从其更新站点获取该更新。 如果您有SVN 1.7.x命令行,则可以使用它来使用svn status命令检查WC和该文件夹。 For whatever reason, it looks like the SVNKit 1.7.x API (which is still in beta) does not t ... -
“右键单击>团队>显示属性”您可以在“SVN属性”视图中编辑它们。 "Right-click > Team > Show Properties" You can edit them in the "SVN Properties" View.