Guest User

Untitled

a guest
Dec 14th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. $(document).on('change', '#tblhotel-int_zone_id', function(e){
  2. var zoneId = $(this).val();
  3. var form_data = {
  4. zone: zoneId
  5. };
  6. $.ajax({
  7. url: "state",
  8. type: "POST",
  9. data: form_data,
  10. success: function(response)
  11. {
  12. alert(response);
  13. }
  14. });
  15. });
  16.  
  17. public function beforeAction($action) {
  18. $this->enableCsrfValidation = false;
  19. return parent::beforeAction($action);
  20. }
  21.  
  22. var form_data = {
  23. zone: zoneId,
  24. _csrf: yii.getCsrfToken()
  25. };
  26.  
  27. <script>
  28. $.ajaxSetup({
  29. data: <?= yiihelpersJson::encode([
  30. yii::$app->request->csrfParam => yii::$app->request->csrfToken,
  31. ]) ?>
  32. });
  33. </script>
  34.  
  35. var csrfToken = $('meta[name="csrf-token"]').attr("content");
  36. $.ajax({
  37. url: 'request',
  38. type: 'post',
  39. dataType: 'json',
  40. data: {param1: param1, _csrf : csrfToken},
  41. });
  42.  
  43. public function beforeAction($action) {
  44. if($action->id == "action name need to disable")
  45. $this->enableCsrfValidation = false;
  46. return parent::beforeAction($action);
  47. }
  48.  
  49. 'components' => [
  50. 'request'=>[
  51. 'csrfParam'=>"othername"
  52. ],
  53. ...
  54.  
  55. 'components' => [
  56. 'request' => [
  57. 'cookieValidationKey' => 'unique code',
  58. 'csrfCookie' => ['httpOnly' => true, 'path' => '/admin/'],
  59. ],
  60. ],
  61.  
  62. 'components' => [
  63. 'request' => [
  64. 'cookieValidationKey' => 'unique code',
  65. 'csrfCookie' => ['httpOnly' => true, 'path' => '/'],
  66. ],
  67. ],
  68.  
  69. var form_data = {
  70. zone: zoneId
  71. };
  72. form_data[yii.getCsrfParam()]=yii.getCsrfToken();
Add Comment
Please, Sign In to add comment