0

submitform()은 데이터를 가져 오지 않습니다. Chrome 콘솔에 ReferenceError : $이 (가) 정의되어 있지 않습니다.. 코드에 이상이 있습니까? enter image description here

var app = angular.module('app', []); 
 
    app.controller('testimonialController', function($scope, $http) { 
 
     $scope.formdata = {}; 
 
     $scope.submission = false; 
 
     $scope.submitform = function($scope, $http) { 
 
     $http({ 
 
      method: 'POST', 
 
      url: 'sendmail.php', 
 
      data: $.param($scope.formdata), // pass in data as strings 
 
      headers: { 
 
      'Content-Type': 'application/x-www-form-urlencoded' 
 
      } // set the headers so angular passing info as form data (not request payload) 
 
     }). 
 
     success(function() { 
 
      console.log("send successfuly"); 
 
     }). 
 
     error(function() { 
 
      console.log("It is failed"); 
 
     }); 
 
     }; 
 
    });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div id="contact-form" ng-controller="testimonialController" ng-app="app"> 
 
    <h1 id="contact">Contact</h1> 
 
    <pre>Form data: {{formdata}}</pre> 
 
    <p>Take a look around the site, Do you have something in mind you would like to let me know .You can contact me by filling the form below or email [email protected]</p> 
 
    <form ng-submit="submitform()"> 
 
    <div class="form-wrap"> 
 
     <label for="name">Name</label> 
 
     <input type="text" name="name" ng-model="formdata.name" placeholder="Name" required> 
 
     <br> 
 

 
    </div> 
 
    <div class="form-wrap"> 
 
     <label for="email">Email</label> 
 
     <input type="email" name="email" ng-model="formdata.email" placeholder="Email" required> 
 
     <br> 
 

 
    </div> 
 
    <div class="form-wrap"> 
 
     <label for="comment">Message</label> 
 
     <br> 
 
     <textarea name="comment" id="comment" ng-model="formdata.comment" placeholder="Comment" cols="30" rows="10" required></textarea> 
 
     <br> 
 

 
    </div> 
 
    <input type="submit" name="submit" value="Send"> 
 
    </form> 
 
</div>
이 사용 enter image description here

$http({ 
    method : 'POST', 
    url  : 'sendmail.php', 
    data : $scope.formdata, // pass in data as strings 
    headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload) 
}). 
+0

왜'$ scope.formdata'뿐만 아니라'data : $ .param ($ scope.formdata)'를 사용합니까? – Jonas

+0

@Jeyp 방금이 자습서를 따라했습니다. http://webdevmatters.wordpress.com/2014/07/28/processing-a-form-with-angularjs-php/ – Muhammed

+0

@Jeyp 콘솔 오류 ** TypeError : 속성 ' formdata 'of undefined ** $ .param을'data : $ scope.formdata'로 제거했을 때 – Muhammed

답변

1

data: $.param($scope.formdata)

이 줄은 jQuery의 $.param 방법을 사용하는 콘솔 메시지입니다.

+0

함수에서 jQuery를 사용하지 않습니다. – Muhammed

+0

@MuhammedAthimannil - 예, 있습니다. 나는 당신이 링크 한 기사를 인용하고있다.'Ok, 솔직히 말해서, 빠른 속임수가 여기에있다. 나는 데이터를 보낼 수 있도록 jQuery의 $ .param을 사용하고있다 .' – Jonas

+0

jQuery를 사용하지 않는 모든 솔루션? – Muhammed

관련 문제