Hello. Recently I started working with the yii framework I ran into the problem of using ajax and jquery. On the Internet, I found some implementation of ajax queries using jquery:

<?=CHtml::ajaxSubmitButton('Принять', $this->createUrl('register/update/'), array( 'type' => 'post', 'beforeSend' => 'js:function(){ $(".operation") .text("bla-bla-bla") .fadeTo(0, 1); }', 'data' => array('Register' => array( 'id' => 'js:$(this).parent().parent().find("input.id").val()', 'name' => 'js:$(this).parent().parent().find("input#name").val()', 'surname' => 'js:$(this).parent().parent().find("input#surname").val()', )), 'success' => 'function (data){ $(".operation") .html(data) .fadeTo(0, 1) .fadeTo(2000, 0); return false; }', ), array( 'class' => 'submit', ) );?> 

This code works, but I don’t understand how to use variables here. Those. I want to, after the execution of the request, I could access the element through $ (this) .parent () ... moving away from the currently pressed button, then put it into a variable and carry out further operations with it. The entry 'complate' => 'js:var val = js:$(this).parent()...', gives an error, but this error code does not produce: 'complate' => 'js:alert("bla-bla-bla")', (I put this code after' beforeSend ') If anyone knows how to properly use variables here, tell me pliz. And another question is whether it is worthwhile to apply this kind of ajax processing in yii or should we use the standard method, i.e. in js file handle pressing this button?

  • 3
    Such situations I call the struggle with the framework. PHP for PHP, or PHP for js. I do not know. In any case, I would not do that. It is better to simply make a regular button, or submit, when loading a DOM, hang a mouse click handler on it and play for fun. - nolka

1 answer 1

'complate' => new CJavaScriptExpression ("YOUR CODE"); // then? not that?