doufu3718
2017-06-10 04:22
浏览 81
已采纳

Ajax成功中Laravel路由的多个参数

I want to create dynamic buttons in Laravel after Ajax Success Method. I have been able to do that as well. But the problem arises when I try to pass the route in the anchor tag. I am adding the full JavaScript code for ease of understanding:

var data = JSON.parse(data);
var finalData = '';
var search_body_data =  $("#searchTableBody");
for (i = 0; i < data.length; i++) {
     finalData = finalData + ` <tr> <td> ${data[i]['data_id']} </td> `;
     finalData = finalData + ` <td> ${data[i]['type']} </td> `;
     finalData = finalData + ` <td><a class="btn btn-primary btn-block" href="{{ route('notification_detail',['type'=>data[i]['type'],'doc_id'=>str_replace('/','-',data[i]['data_id']),'part'=>"0"]) }}">Detail</a></td> `;
     finalData = finalData + ` </tr> `;
}
search_body_data.html(finalData);

But this gives me the following error: Use of undefined constant data - assumed 'data'. I have also tried:

${'type'=>data[i]}

But it also gives the same error. Also tried some other variations but still no luck. Any work around will be highly appreciated.

图片转代码服务由CSDN问答提供 功能建议

我想在Ajax成功方法之后在Laravel中创建动态按钮。 我也能做到这一点。 但是当我尝试在锚标签中传递路由时,问题就出现了。 我正在添加完整的JavaScript代码以便于理解:</ p>

  var data = JSON.parse(data); 
var finalData =''; 
var search_body_data = $(“  #searchTableBody“); 
for(i = 0; i&lt; data.length; i ++){
 finalData = finalData +`&lt; tr&gt;  &LT; TD&GT;  $ {data [i] ['data_id']}&lt; / td&gt;  `; 
 finalData = finalData +`&lt; td&gt;  $ {data [i] ['type']}&lt; / td&gt;  `; 
 finalData = finalData +`&lt; td&gt;&lt; a class =“btn btn-primary btn-block”href =“{{route('notification_detail',['type'=&gt; data [i] [  'type'],'doc_id'=&gt; str_replace('/',' - ',data [i] ['data_id']),'part'=&gt;“0”])}}“&gt;详细信息&lt;  / A&GT;&LT; / TD&GT;  `; 
 finalData = finalData +`&lt; / tr&gt;  `; 
} 
 
insearch_body_data.html(finalData); 
 </ code> </ pre> 
 
 

但是这给了我以下错误:使用未定义的常量数据 - 假设'数据 “</ strong>即可。 我也尝试过:</ p>

  $ {'type'=&gt; data [i]} 
 </ code> </ pre> 
 
 

但是 它也会给出同样的错误。 还尝试了一些其他的变化,但仍然没有运气。 任何解决方法都将受到高度赞赏。</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题