angularjs http post方法

时间:2016-07-20 03:53:28

标签: javascript angularjs mongodb

尝试将某些东西发回到mongodb然而它没有发送任何东西,当我点击提交它的传递{}回到cmd并且网络控制台挂起待定然后它将失败当它花了很长时间发布。

有人可以对这个问题有所了解,谢谢。

HTML:

#include <stdio.h>
#include <stdlib.h>

typedef struct node {
    int value;
    struct node *next;
} node_t;

void insert (node_t **head, int num)
{
    /* Create new node to insert */
    node_t *node = calloc (1, sizeof *node);
    if (node == NULL) {
        fprintf (stderr, "error: virtual memory exhusted.\n");
        exit (2);
    }
    node->value = num;
    node->next = NULL;

    /* Insert node at end */
    if (!(*head))               /* handle first node */
        *head = node;
    else if (!(*head)->next)    /* handle second     */
        (*head)->next = node;
    else {                      /* handle remaining  */
        node_t *cur = *head;
        while (cur->next)
            cur = cur->next;
        cur->next = node;
    }
}

int main (void) {

    int tmp;
    node_t *head = NULL, *iter = NULL;

    /* Insert nodes to end of list (from stdin) */
    while (scanf (" %d", &tmp) == 1)
        insert (&head, tmp);

    /* Traverse list and print out all node values */
    iter = head;
    while (iter) {
        printf ("%d\n", iter->value);
        iter = iter->next;
    }

    /* Free the list */
    iter = head;
    while (iter->next) {
        node_t *victim = iter;
        iter = iter->next;
        free (victim);
    }
    if (iter) free (iter);

    return 0;
}

服务:

$ cat ../dat/10int_nl.txt
8572
-2213
6434
16330
3034
12346
4855
16985
11250
1495

获取用户:我从数据库中获取用户。

$ valgrind ./bin/llvalgrind <../dat/10int_nl.txt
==31935== Memcheck, a memory error detector
==31935== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==31935== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==31935== Command: ./bin/llvalgrind
==31935==
8572
-2213
6434
16330
3034
12346
4855
16985
11250
1495
==31935==
==31935== HEAP SUMMARY:
==31935==     in use at exit: 0 bytes in 0 blocks
==31935==   total heap usage: 10 allocs, 10 frees, 160 bytes allocated
==31935==
==31935== All heap blocks were freed -- no leaks are possible
==31935==
==31935== For counts of detected and suppressed errors, rerun with: -v
==31935== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 1 from 1)

发布行动:

<input type="text" ng-model="vm.user">
<input type="text" ng-model="vm.pass">

Server.js app.post返回db

function _postUser(user,pass){
        var params = {
            user: user,
            pass:pass
        }
        return $http({
            method: 'POST',
            url: '/loginDB',
            params: params
        })
    }

编辑:它的发布但是现在采用了ng-model,我知道ng-model出了问题,但是我无法理解它。

vm.getUsers = function (){
        homeService.getUsers()
            .then(function(response){
                vm.users = response.data;
                console.log(vm.users);
            });
    }

1 个答案:

答案 0 :(得分:0)

尝试将params密钥更改为data

 return $http({
        method: 'POST',
        url: '/loginDB',
        data: params
    })

在html中,你也有两个输入相同的模型,

控制器声明,

vm.newuser = {user:'',pass:''};

html

<input type="text" ng-model="vm.newuser.user">
<input type="text" ng-model="vm.newuser.pass">