[英]angularjs can't connectwith php using http
我要添加一個在網站上找到的聯系表格,該表格可以在php方面為我提供幫助。 我唯一的問題似乎是我似乎無法在所獲得的控制台中將JS連接到我的PHP。 關於我如何可以互相交流和工作的任何想法:)謝謝:)
angular.js:8661 POST http:// localhost:3000 / processForm.php 404(未找到)
我的js http看起來很喜歡
$scope.sendMessage = function( input ) {
$http({
method: 'POST',
url: 'processForm.php',
data: input,
headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' }
})
.success( function(data) {
if ( data.success ) {
$scope.success = true;
} else {
$scope.error = true;
}
});
}
我的PHP看起來像
<?php
$response = array( 'success' => false );
$formData = file_get_contents( 'php://input' );
$data = json_decode( $formData );
if ( $data->submit && empty( $data->honeypot ) ) {
$name = $data->name;
$email = $data->email;
$message = $data->message;
if ( $name != '' && $email != '' && $message != '' ) {
$mailTo = 'hidden@gmail.com';
$subject = 'New contact form submission';
$body = 'From: ' . $name . "\n";
$body .= 'Email: ' . $email . "\n";
$body .= "Message:\n" . $message . "\n\n";
$success = mail( $mailTo, $subject, $body );
if ( $success ) {
$response[ 'success' ] = true;
}
}
}
echo json_encode( $response );
?>
文件結構是
│ 404.html
│ favicon.ico
│ index.html
│ robots.txt
│ processForm.php
│
├───images
│ yeoman.png
│
├───scripts
│ │ contact.js
│ │
│ │
│ │
│ └───controllers
├───styles
│ main.css
│ style.css
│
└───views
contact.html
main.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.