Всем привет,
Надо отправить post-запрос средствами ajax. Делаю в смарти-темплейте :
Код:
var HRef = "{$base_url}main/send_contact_us"
alert( "HRef::" + HRef)
var DataArray = { // 'csrf_test_name': $.cookie('csrf_cookie_name')
"name": encodeURIComponent(contact_us_name),
"email": encodeURIComponent(contact_us_email),
"message": encodeURIComponent(contact_us_message),
"capture": encodeURIComponent(contact_us_capture),
'csrf': '{$security_token}' // $security_token - это Security::token()
};
alert( "++DataArray::"+var_dump(DataArray) )
jQuery.ajax({
url: HRef,
type: "POST",
data: DataArray,
success: onSentContactUs,
dataType: "json"
});
}
function onSentContactUs(data) {
alert( "data::" + var_dump(data) )
if (data.ErrorCode != 0) {
alert(data.ErrorMessage)
$('#' + data.ErrorFieldName).focus();
return
}
$("#contact_us_name").val("")
$("#contact_us_email").val("")
$("#contact_us_message").val("")
$("#contact_us_capture").val("")
ShowCaptureImage();
alert("Your message was sent !")
}
И в контроле :
Код:
if ($send_contact_us_word != $capture or $blog_capture_expired_time < time()) {
Appfuncs::instance()->DebToFile( 'Wrong capture::' , false );
header("Content-Type: application/json");
echo json_encode( array( 'ErrorMessage' => 'Invalid Capture', 'ErrorCode' => 1, 'ErrorFieldName' => 'contact_us_capture' ) );
return;
}
Контрол нормально вызывается и строка
Код:
Appfuncs::instance()->DebToFile( 'Wrong capture::' , false );
выводит строку в отладочный текстовый файл но не вызывается функция возврата onSentContactUs
В чем может быть проблема или как еще можно отлаживать ?
access.log:
Код:
127.0.0.1 - - [24/Sep/2013:10:01:51 +0300] "POST /main/send_contact_us HTTP/1.1" 200 7411 "http://local-kohana.com/contact_us" "Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20110328 Firefox/17.0"