【问题标题】:Ajax not sending response when sending php variable LARAVEL发送 php 变量 LARAVEL 时 Ajax 未发送响应
【发布时间】:2021-03-20 19:43:14
【问题描述】:

向控制器发送 ajax 请求时,我收到一条成功警报消息。

查看


  $(".SendEvents").click(function(e){
 
       e.preventDefault();
 
       var ids = $(this).attr("id"); 
 
       $.ajax({
          type:'POST',
          url:"{{ route('ajaxRequest.post') }}",
          data:{id:ids},
          success:function(data){
             alert(data.success);
          }
       });
 
   });

控制器

   {
       $input = $request->all();

       return response()->json(['success'=>'Your Event Are Sent Successfully to Your Email']);
   }

但是当向发送的数据添加 php 变量时,我没有收到如下响应警报

查看


       e.preventDefault();

       var ids = $(this).attr("id"); 
       var sss= <?php echo "hello" ?>
       $.ajax({
          type:'POST',
          url:"{{ route('ajaxRequest.post') }}",
          data:{id:ids,sss:sss},
          success:function(data){
             alert(data.success);
          }
       });

   });

【问题讨论】:

  • user var sss=' ';

标签: php jquery ajax laravel


【解决方案1】:

轻松将此变量放在单引号/双引号中

var sss= "<?php echo "hello" ?>";

【讨论】:

    猜你喜欢
    • 2015-09-30
    • 2012-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多