Last active
January 12, 2021 11:47
-
-
Save sametatabasch/7565e8b62e5ec151e2b4 to your computer and use it in GitHub Desktop.
CKEditor Ajax Post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$content = $_POST['editor1']; | |
if(empty($content)){ | |
$response= array('status'=>'danger','msg'=>'İçerik Boş'); | |
header('Content-Type: application/json'); | |
echo json_encode($response); | |
}else{ | |
$response= array('status'=>'success','msg'=>$content); | |
header('Content-Type: application/json'); | |
echo json_encode($response); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>CKEditor Örnek</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script> | |
<!--Ckedtor ana dosyasını ekleyelim--> | |
<script src="ckeditor/ckeditor.js"></script><!--ckeditor dosyaları bu dosya ile aynı dizinde--> | |
<!-- Bootstrap --> | |
<!-- Latest compiled and minified CSS --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> | |
<!-- Latest compiled and minified JavaScript --> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> | |
<!-- Bootstrap --> | |
<style> | |
#ajaxResult{ | |
position: fixed; | |
} | |
</style> | |
</head> | |
<body> | |
<form method="post" action="ajax.php" class="ajaxForm"> | |
<textarea name="editor1" id="editor1" rows="10" cols="80" class="ckeditor"> | |
Gelişmiş elemanları bulunan metin alanı | |
</textarea> | |
<input type="submit" value="Kaydet"> | |
</form> | |
<script> | |
CKEDITOR.replace('editor1',{ | |
filebrowserBrowseUrl:'/fileman/index.html', // Öntanımlı Dosya Yöneticisi | |
filebrowserImageBrowseUrl:'/fileman/index.html?type=image', // Sadece Resim Dosyalarını Gösteren Dosya Yöneticisi | |
removeDialogTabs: 'link:upload;image:upload' // Upload işlermlerini dosya Yöneticisi ile yapacağımız için upload butonlarını kaldırıyoruz | |
}); | |
$(function () { | |
$('.ajaxForm').on('submit', function () { | |
CKEDITOR.instances['editor1'].updateElement();//CKEditor bilgileri aktarıyor. | |
$.ajax({ | |
type : 'POST', | |
url : $(this).attr('action'), | |
data : $(this).serializeArray(), | |
success: function (returnData) { | |
$('body').append( | |
'<div id="ajaxResult" class="alert alert-' + returnData['status'] + ' alert-dismissable">' + | |
'<i class="fa fa-check"></i>' + | |
'<button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>' + | |
'' + returnData['msg'] + | |
'</div>' | |
); | |
$('#ajaxResult').css({ | |
'left': (window.innerWidth - jQuery('#ajaxResult').width()) / 2, | |
'top' : (window.innerHeight - jQuery('#ajaxResult').height()) / 2 | |
}); | |
} | |
}); | |
return false; | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment