Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.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
Javascript 如何在http post中传输数据输入_Javascript_Angularjs - Fatal编程技术网

Javascript 如何在http post中传输数据输入

Javascript 如何在http post中传输数据输入,javascript,angularjs,Javascript,Angularjs,我想在没有php的情况下使用我的web服务。使用Angular,如何使用表单的输入参数执行web服务。这是一个REST配置。我试着问邮递员 mY WEB PAGE : ---------------------------------------------------------------------------- <!DOCTYPE html> <html> <head> <meta content="text/

我想在没有php的情况下使用我的web服务。使用Angular,如何使用表单的输入参数执行web服务。这是一个REST配置。我试着问邮递员

mY WEB PAGE : 


----------------------------------------------------------------------------


 <!DOCTYPE html>
<html>
    <head>
        <meta content="text/html; charset=windows-1252" http-equiv="content-type">
        <title>connexion.html</title>
        <script type="text/javascript" src="angular.js"></script>
    </head>

    <form ng-submit ng-controller="valController" data-action="http://localhost:8080/globalAlfWs/cxf/user/login">

        <input type="text" name="login" ng-model="login">
        <input type="text" name="password" ng-model="password">
        <input type="submit" id="submit" value="Submit">

    </form>
</html>
我的小提琴:

编辑/

var appel = angular.module("appel",[]);
appel.controller('ValController',函数($scope,$http){


它可以工作!!

这应该对您有效,您错过了对ngSubmit上提交函数的调用:

 <!DOCTYPE html>
<html>
    <head>
        <meta content="text/html; charset=windows-1252" http-equiv="content-type">
        <title>connexion.html</title>
        <script type="text/javascript" src="angular.js"></script>
    </head>

    <form ng-submit="submit()" ng-controller="valController">

        <input type="text" name="login" ng-model="login">
        <input type="text" name="password" ng-model="password">
        <input type="submit" id="submit" value="Submit">

    </form>
</html>

如果您还有任何问题,请告诉我。

如果您在表单上使用
submit
按钮和
submit
操作,则需要去掉
data action
属性。否则,submit按钮会在操作URL上触发表单提交,而ajax请求将不起作用

这是我对您的URL所做的修改,它在我使用的模拟URL上工作。


你需要一个
ng点击
来调用submit。请制作fiddle和plunker并提供更多详细信息它是否真的进入了提交功能?我添加了我的js fiddle,是的,它在提交功能中吗web服务返回我一个json响应我想要这个响应,即使参数错误或不存在^^ web服务发出请求在网络选项卡中,是,响应是什么?HTTP错误415由于“内容类型”而不支持媒体类型。我不明白为什么…看起来您的服务器不接受此请求的JSON数据。您使用的是哪台服务器,以及您的请求解析器是否设置为支持JSON?我使用的是TomCat服务器。但当我将内容参数更改为“undefined”时,它会工作。。。。
    var data = new FormData;

    $scope.submit = function(){
        data.append("login",$scope.login);
        data.append("password",$scope.password);
        $http({
            method:'POST',
            url:"http://localhost:8080/globalAlfWs/cxf/user/login",
            data : data,
           headers: {
                'Content-Type': undefined
            }
        })
            .success(function(response){
                $scope.result = response;
                console.log($scope.result);
            })
            .error(function(){
                console.log("error");
            });
    };
});
 <!DOCTYPE html>
<html>
    <head>
        <meta content="text/html; charset=windows-1252" http-equiv="content-type">
        <title>connexion.html</title>
        <script type="text/javascript" src="angular.js"></script>
    </head>

    <form ng-submit="submit()" ng-controller="valController">

        <input type="text" name="login" ng-model="login">
        <input type="text" name="password" ng-model="password">
        <input type="submit" id="submit" value="Submit">

    </form>
</html>
    $scope.submit = function(){
        var data = new FormData;
        data.append("login", $scope.login);
        data.append("password", $scope.password);
        $http({
            method:'POST',
            url:"http://localhost:8080/globalAlfWs/cxf/user/login",
            data : data,
           headers: {
                'Content-Type': undefined
            }
        })
            .success(function(response){
                $scope.result = response;
                console.log($scope.result);
            })
            .error(function(){
                console.log("error");
            });
    };
});
<form ng-submit ng-controller="valController" >