dounan9070 2016-10-18 03:29
浏览 47
已采纳

将角形式提交到php文件[重复]

This question already has an answer here:

I'm trying to submit the form below to a php file called time.php, but its not working, even when I check the console there are no errors, its just clear. I'm not sure where I may be going wrong.

<form ng-controller="testCtrl" class="customform" data-ng-init="init()">
<div class="s-10 1-10">
    <input ng-model="firstName" pattern=".{2,100}" title="2 to 100 Characters" placeholder="First Name" type="text" required />
</div>
<div class="s-10 1-10">
    <input ng-model="lastName" pattern=".{5,255}" title="5 to 255 Characters" placeholder="Last Name" type="text" required />
</div>
<div class="s-12 l-10"><input ng-model="acNumber" placeholder="A/C Number" title="Employee Number, i.e c1234567" type="text" required /></div>
<div class="s-12 l-10"><input ng-model="email" placeholder="Email" title="Email" type="email" required /></div>
<div class="s-12 l-10">
    <select ng-model="selectedRequestType" ng-options="requestType as requestType.type for requestType in requestTypes" required="required">
        <option value="" disabled selected>Request Type</option>
    </select>
</div>
<div class="s-12 l-10">
    <select ng-show="selectedRequestType.type == 'Work Request'" ng-model="selectedWorkRequestType" ng-options="workRequestType as workRequestType.type for workRequestType in workRequestTypes">
        <option value="" disabled selected>Work Request Type</option>
    </select>
</div>
<div class="s-12 l-10">
    <select ng-show="selectedWorkRequestType.type == 'New file(s) from source'" ng-model="selectedFile" ng-options="file as file.type for file in files">
        <option value="" disabled selected>Files</option>
    </select>
</div>
<div class="s-12 l-10">
    <select ng-show="selectedWorkRequestType.type == 'New file(s) from source'" ng-model="selectedLibrary" ng-options="library as library.type for library in libraries">
        <option value="" disabled selected>Does Library Exist</option>
    </select>
</div>
<div class="s-12 l-10">
    <select ng-show="selectedWorkRequestType.type == 'Code Automation' || selectedWorkRequestType.type == 'Amendments to existing code'" ng-model="selectedOutput" ng-options="outputType as outputType.type for outputType in outputTypes">
        <option value="" disabled selected>Output</option>
    </select>
</div>
<div class="s-12 l-10">
    <select ng-show="selectedLibrary.type == 'Yes' || selectedRequestType.type == 'Incident'" ng-model="selectedPlatformOutput" ng-options="platformOutput as platformOutput.type for platformOutput in platformOutputs">
        <option value="" disabled selected>Platform Output</option>
    </select>
</div>
<div class="s-12 l-10">
    <input ng-show="selectedOutput.type == 'SAS' || selectedPlatformOutput.type =='SAS'" ng-model="sasLibraryName" type="text" placeholder="SAS Library Name: SPDS Exploit" />
</div>
<div class="s-12 l-10">
    <input ng-show="selectedOutput.type == 'SAP IQ' || selectedPlatformOutput.type =='SAP IQ'" ng-model="sapIQtext" placeholder="SAP IQ" >
</div>
<div class="s-12 l-10">
    <input ng-show="selectedOutput.type == 'Hadoop' || selectedPlatformOutput.type =='Hadoop'" placeholder="Library Name: HDFS_Exploit" ng-model="hadoop" />
</div>
<div class="s-12 l-10">
    <input ng-show="selectedWorkRequestType.type == 'Amendments to existing code'" placeholder="Output Dataset Name" ng-model="outputDataset" type="text"/>
</div>
<div class="s-12 l-10">
    <input ng-show="selectedLibrary.type == 'No'" type="text" ng-model="productName" Placeholder="Product Name" />
</div>
<div class="s-12 l-10">
    <input ng-show="" placeholder="Upload Text File" type="file" ng-model="uploadTextFile" title="Please upload a txt file with the layout - to " multiple />
</div>
<div class="s-12 l-10">
    <input ng-show="selectedRequestType.type == 'Incident'" type="text" ng-model="tableName" placeholder="Dataset/Table Name" />
</div>
<div class="s-12 l-10">
    <textarea placeholder="Special Instructions" ng-model="specialInstruction" rows="5"></textarea>
</div>
<div class="s-12 l-10">
    <input ng-show="selectedRequestType.type == 'Incident'" ng-model="uploadScreenshot" placeholder="Upload Screenshot of error" type="file" multiple/>
</div>
<div class="s-12 l-10">
    <select ng-show="selectedRequestType.type == 'Work Request'" ng-model="selectedFrequency" ng-options ="frequency as frequency.type for frequency in frequencies">
        <option value="" disabled selected>Frequency</option>
    </select>
</div>
<div class="s-12 l-10">
    <select ng-show="selectedFrequency.type == 'Weekly'" ng-model="selectedWeekly"  ng-options ="weekly as weekly.type for weekly in weeklies">
        <option value="" disabled selected>Weekly Frequency</option>
    </select>
</div>
<input type="hidden" ng-model="token" value="<?php echo Token::generate()?>">
<div class="s-4"><button type="submit" id="submit" class="btn-custom btn btn-large btn-block" ng-click="sendRequest()">Request</button></div>

Please note: ng-app="app" is located in the header:

<!DOCTYPE html>
<html lang="en-US" ng-app="app">


The following code is the controller, and I believe the issue lies somewhere in here:

    var app = angular.module('app', []);
app.controller('testCtrl', ['$scope', '$http', function($scope, $http) {

$scope.sendRequest = function(){
    var data= {
        'firstName' :$scope.firstName,
        'lastName' :$scope.lastName,
        'acNumber' :$scope.acNumber,
        'email' :$scope.email,
        'selectedRequestType' :$scope.selectedRequestType,
        'selectedWorkRequestType' :$scope.selectedWorkRequestType,
        'selectedOutput' :$scope.selectedOutput,
        'selectedFrequency' : $scope.selectedFrequency,
        'selectedWeekly' : $scope.selectedWeekly,
        'selectedFile' : $scope.selectedFile,
        'selectedLibrary' : $scope.selectedLibrary,
        'selectedPlatformOutput' : $scope.selectedPlatformOutput,
        'productName' : $scope.productName
    };


    $http({
        url: "time.php",
        method: "POST",
        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
        data: data
    }).success(function(data, status, headers, config) {
        //Success code
    }).error(function(xhr) {
        //Failure code
        console.log(data);
        console.log(xhr.responseText);
    });

    return false;
  //  $window.location.href ='/time.php';

};

$scope.init = function (){
    $scope.workRequestType = 'test';
    $scope.requestTypes = [
        {'type':'Work Request'},
        {'type': 'Incident'}
    ];
    $scope.workRequestTypes = [
        {'type': 'Amendments to existing code'},
        {'type': 'Code Automation'},
        {'type': 'New file(s) from source'}
    ];
    $scope.outputTypes = [
        {'type': 'SAS'},
        {'type':'SAP IQ'},
        {'type': 'Hadoop'}
    ];
    $scope.frequencies = [
        {'type' : 'Daily'},
        {'type': 'Monthly'},
        {'type': 'Weekly'}
    ];
    $scope.weeklies = [
        {'type': 'Monday'},
        {'type':'Tuesday'},
        {'type': 'Wednesday'},
        {'type':'Thursday'},
        {'type':'Friday'},
        {'type':'Saturday'},
        {'type':'Sunday'}
    ];
    $scope.files = [
        {'type': 'New File(s)'},
        {'type': 'Add to existing file received'}
    ];
    $scope.libraries = [
        {'type':'Yes'},
        {'type':'No'}
    ];
    $scope.platformOutputs = [
        {'type': 'SAS'},
        {'type':'SAP IQ'},
        {'type': 'Hadoop'}
    ];
    $scope.firstName= null;
    $scope.lastName= null;
    $scope.acNumber= null;
    $scope.email= null;
    $scope.selectedRequestType= null;
    $scope.selectedWorkRequestType= null;
    $scope.selectedOutput= null;
    $scope.sasLibraryName = null;
    $scope.sasIQtext = null;
    $scope.selectedFrequency = null;
    $scope.selectedWeekly = null;
    $scope.selectedFile = null;
    $scope.selectedLibrary = null;
    $scope.selectedPlatformOutput = null;
    $scope.productName = null;
};
}]);

I'm still learning Angular, so I may have made a simple error

</div>
  • 写回答

1条回答 默认 最新

  • dongposhi8677 2016-10-18 03:45
    关注

    If the HTTP POST request is taking place, but PHP is not able to access the POST variables, try converting the data from an object to a string.

    $http({
            url: "time.php",
            method: "POST",
            headers: {'Content-Type': 'application/x-www-form-urlencoded'},
            data: $httpParamSerializerJQLike(data),
        })
    

    The string should look like: firstName=John&acNumber=1234

    Pass the $httpParamSerializerJQLike service into your controller with:

    app.controller('testCtrl', ['$scope', '$http', '$httpParamSerializerJQLike', function($scope, $http, $httpParamSerializerJQLike) {
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题