我已經在stackoverflow中搜索的問題,並發現很少的答案,但非他們幫助我。所以我再次發佈它。我的PHP的形式在本地主機POST方法工作正常,但相同的代碼是不是在服務器(Linux服務器)工作,我不知道實際的問題是什麼。請幫助PHP POST metod不與jQuery的Ajax或無Ajax工作
- 形式,我想提交
<form class="forma" id="forma" method="POST" action="contact-form.php" name="myForm" autocomplete="off">
<div class="formWrapper">
<div class="group">
<input type="text" name="name" id="name">
<span class="highlight"></span>
<span class="bar"></span>
<label>Name</label>
<p class="error-red"></p>
</div>
<div class="group">
<input type="text" name="eMail" id="eMail">
<span class="highlight"></span>
<span class="bar"></span>
<label>Email</label>
<p class="error-red"></p>
</div>
<div class="group">
<input type="text" name="mobileNo" id="mobileNo">
<span class="highlight"></span>
<span class="bar"></span>
<label>Mobile no.</label>
<p class="error-red"></p>
</div>
<div class="group">
<input type="text" name="message" id="message">
<span class="highlight"></span>
<span class="bar"></span>
<label>Message</label>
</div>
<div class="captchaWrapper">
<img src="captcha.php?rand=<?php echo rand(); ?>" id="captchaimgCont" style="margin-right: 14px;" alt="captcha">
<a href="javascript: refreshCaptcha();" class="clickTorefreshAnchor">
<i class="fa fa-refresh clickTorefresh" id="caprefresh">
</i>
</a>
<div class="captchaInputWrapper group">
<input type="text" id="6_letters_code" name="captcha">
<span class="highlight"></span>
<span class="bar"></span>
<label>Enter the code here:</label>
<p class="error-red"></p>
</div>
</div>
<div class="submit submitBtn" id="consubmit">
<button type="submit" name="sendmail" id="sendmail" class="sendMailBtn">Submit
</button>
</div>
</div>
<div class="clear"></div>
</form>
- 我的jquery Ajax代碼
- 我的PHP代碼
jQuery(document).ready(function() {
jQuery("#forma").submit(function(e) {
e.preventDefault();
e.stopImmediatePropagation();
jQuery('#sendmail').html('Please wait...');
jQuery.ajax({
type: "post",
url: './contact-form.php',
data: jQuery("#forma").serialize(),
dataType: "json",
success: function(data) {
jQuery('p.error-red').html('');
if ('success' == data.result) {
//jQuery("#forma")[0].reset();
//jQuery('#response').append('<p class="successMessage">' + data.msg + '</p>');
// jQuery('#sendmail').html('Submit');
window.location.href = "https://www.mrpmediaworks.com/thanks.php";
}
if ('error' == data.result) {
var arr = data.msg;
var element_arr = data.fieldname;
count = '0';
jQuery.each(arr, function(index, value) {
if (value.length != 0) {
jQuery('input[name=' + element_arr[count] + ']').parent('.group').find('p.error-red').html(value);
}
count++;
});
jQuery('#sendmail').html('Submit');
}
}
});
return false;
});
});
<?php
session_start();
require_once('config.php');
$email = '';
$fieldname = array();
$msg = array();
$result = '';
$count = '';
$name = $_Post["name"];
$contact = $_Post["mobileNo"];
$email = $_Post["eMail"];
$msg_query = $_Post["message"];
$captcha = $_Post["captcha"];
echo $name;
die();
?>
只是測試代碼
相同的代碼工作與獲得
我已嘗試刪除行動形式和可能的組合,但注意工作。 編輯後
4. .htaccess file
# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
這是我的htaccess文件的唯一內容
你的表單在哪裏,我在你的代碼中看不到。 –
重複的http://stackoverflow.com/questions/5004233/jquery-ajax-post-example-with-php –
@AnkitShah不是真的重複。他需要返回具有data.result屬性的json – mplungjan