Now I am doing a project, and when you click on some buttons, the Ajax should work. Example: to rate the "+" article. Clicking on + leaves the AJAX request, but the fact is that in the debugger its time is 1.883 MS and oscillates around it each time. And the matter is not in what is in action, because even if the action only has return true; then the request is executed 1.443 MS, which seems to be too much. Or let's say that a modal window opens, its content opens too somewhere in a second. What could be causing this at all? Here is the code of the example of the execution of the Ajax. There is nothing superfluous, but nothing at all.

$.ajax({ url: '/profile/like', data: {id: id}, type: "POST", success: function(res) { }, error: function() { } }); 

PS I created a separate test project, so that when you press a button, an AYAX request is sent, and it is sent perfectly. Immediately everything works. And in the project with Yii2, it is just some kind

Controller:

 public function actionUnlike() { $photo = Photo::findOne(Yii::$app->request->post()); // Находим Ρ„ΠΎΡ‚ΠΊΡƒ с этим ID (Π° Ρ‚ΠΎ ΠΏΠ΅Ρ€Π΅Π΄Π°Π΄ΡƒΡ‚ Ρ‡Π΅Ρ€Π΅Π· Π±ΡƒΡ€ΠΏ ΠΊΠ°ΠΊΠΎΠΉ Ρ‚ΠΎ Π»Π΅Π²Ρ‹ΠΉ айдишник Π΅Ρ‰Π΅..) if($photo) Like::unlike(Yii::$app->request->post('id')); // ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ post ID Ρ„ΠΎΡ‚ΠΊΠΈ ΠΈΠ· AJAX (main.js) } 

The static method unlike in the model:

  public static function unlike($id) { $like = Like::find()->where(['user_id' => Yii::$app->user->identity->id, 'photo_id' => $id])->one(); return $like->delete(); } 

Handler inside js

 $.ajax({ url: '/profile/unlike', data: {id: id}, type: "POST", success: function(res) { }, error: function() { } }); } 

Debagger shows that Unlike works for approximately 1,377 ms.

  • it's definitely not a framework, please show me more code: controller and full code for jQuery event handler - Blacknife
  • I added, I will be glad if you help and find something that is problematic - idriverx
  • $photo = Photo::findOne(Yii::$app->request->post()); - why do you pass all post data to the method? - Blacknife
  • Is the server local or not? server response time checked? - Blacknife
  • In the first I fixed it, and passed only the id from POST, thanks. And the second case, yes, the server is local. And then the question is Nubian, but the stupidest question is - not yet asked. How to check server response time on locale? - idriverx

0