首页 \ 问答 \ 解析JSON对象 - Angularjs + PHP(Parsing JSON Object - Angularjs + PHP)

解析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
更新时间:2023-09-17 21:09

最满意答案

我认为你需要清理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 Windows

You 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.
  • 您不能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 ...
  • 无论出于何种原因,看起来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.

相关文章

更多

最新问答

更多
  • 您如何使用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)