following code will implement AJAX-Request as intended. Curiously, it’s only working with yii2-method textinput(). Using yii2-method textarea() or even widget CKEditor doesn’t work- Any ideas how to use AJAX-Request with more comfortable methods but textinput()?
Here is Controllercode:
<?php
namespace frontend\controllers;
use Yii;
use yii\helpers\Json;
use backend\modules\app_einstellung\models\Textbaustein;
use yii\web\Controller;
class TextbausteinController extends Controller {
public function actionBaustein($textId) {
$text = Textbaustein::findOne($textId);
echo Json::encode($text);
}
}
.
.
Here is JQueryCode:
<?=
Dialog::widget();
$script = <<< JS
$('#bez').change(function(){
//$('#mailausgang-inhalt').val('');
var textId=$(this).val();
$.get('textbaustein/baustein',{textId:textId},function(data){
var data=$.parseJSON(data);
krajeeDialog.alert('Fügen Sie eventuell erzeugte Mailvorlagen manuell(Copy&Paste) in Ihren Maileditor ein');
$('#mailausgang-inhalt').attr('value',data.inhalt);
});
});
JS;
$this->registerJS($script);
?>
Okay. Thx for these informations. As it seems, I know so far why event won’t be triggered. It’d be better to know if there are possibilites to get AJAX triggered with alternative elements but textinput().
I can’t believe, that creators of framework just implemented AJAX using textinput(). This argument won’t be accepted by my chief, I assume
So, I did, but of course, I don’t succeed. Following JQuery-code will have no error, but it’s also ineffective for textarea()
$script = <<< JS
$('#bez').change(function(){
//$('#mailausgang-inhalt').val('');
var textId=$(this).val();
$.get('textbaustein/baustein',{textId:textId},function(data){
var data=$.parseJSON(data);
krajeeDialog.alert('Fügen Sie eventuell erzeugte Mailvorlagen manuell(Copy&Paste) in Ihren Maileditor ein');
$('#bez').keypress(function(e) { //won't have any effect
//$('#mailausgang-inhalt').keypress(function(e) { //won't have any effect,too
if(e.which == 13) {
$('#mailausgang-inhalt').attr('value',data.inhalt);
}
});
});
});
How else should I understand ur suggestion [color="#1C2837"][size="2"] to attach an event handler on key press event, in which fire the Ajax call only when the key is ENTER?[/size][/color]