【问题标题】:Sending dynamic id and base url to laravel route in Jquery在 Jquery 中将动态 id 和基本 url 发送到 laravel 路由
【发布时间】:2013-04-23 03:03:31
【问题描述】:

我有一个 jquery ajax 函数,它更新为比赛设置的评分并将其发送到控制器以更改数据库变量。

但是如何从 url 动态获取网站的竞赛 ID 和基本 url 到我的 jquery 函数中?

http://ontwerpwedstrijden.dev/contests/1

这是我正在使用的路由 url。

$(function() {
  $(".radio").on("click",function(e) {  
    // dynamic variables
    var base = 'http://ontwerpwedstrijden.dev';
    var id = 1; // needs to be changed to the current url id
    // Ajax call 
    $.post(base+'/contests/'+id,{ rating: this.value}, function(data) {
      console.log(data);
    });
  });  
});

【问题讨论】:

    标签: php jquery ajax laravel laravel-3


    【解决方案1】:

    看看这个:Get current URL in JavaScript?

    这样您就可以获取 url,然后从中提取您需要的内容(在本例中为 id)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-07
      • 1970-01-01
      • 2017-05-28
      • 1970-01-01
      • 2017-09-21
      • 1970-01-01
      • 2018-05-19
      • 1970-01-01
      相关资源
      最近更新 更多