Got some strange problem, when i use $.post to a php file. The file itself without any post echos ‘someresult’ and when i go $.post the html() of post data is null… Help out plz
$('#podborform').submit(function(){
var phone = $('#tour_selection_phone').val();
if(phone != null && phone != '' && phone.length >= 7){
var values = $(this).serialize();
var qwer = String('captcha');
var url = $(this).attr( 'action' );
$.post( url, values,
function( data ) {
var content1 = $( data ).html();
//content = String(content);
//alert(qwer+' - '+content);
if(content1 == qwer){
alert('Вы не правильно ввели код с картинки, попробуйте еще раз!');
}
if(content1 == 'false'){
alert('Извините произошла ошибка!');
}
if(content1 == 'true'){
alert('Ваша заявка успешно отправлена!');
}
}
);
}else{
alert('Вы не ввели все обязательные поля!');
}
return false;
});
it is connected to php that contains this:
<?php
class mailer{
//var $fields = array();
function __construct(){
if($this->captcha()){
$this->sendmail();
}else{
exit('false');
}
}
function sendmail(){
foreach($_POST as $key=>$post){
$text .= $key.': '.$post.PHP_EOL;
}
if(mail("123@gmail.com", "the subject", $text,
"From: sales@123.ru\r\n"
."Reply-To: {$_POST['email']}\r\n"
."X-Mailer: PHP/" . phpversion())){
exit('true');
}else{
exit('false_mail');
}
}
function captcha(){
require_once('recaptchalib.php');
$privatekey = "123123";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
echo 'captcha'; exit;
} else {
unset($_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
return true;
}
}
}
$mail = new mailer;
?>
.htmlgets the containing HTML.Example
You can use
datadirectly. It will contain the response as a string