简体   繁体   English

在Laravel中将GET参数传递给POST

[英]Passing GET Parameter to POST In Laravel

I'm using jQuery AJAX To pass some map coordinates to a controller with POST. 我正在使用jQuery AJAX通过POST将一些地图坐标传递给控制器​​。 Now I'm wondering. 现在我想知道。

If the current page is 如果当前页面是

site.com/project/2

What would be a good way to pass the 2 also with POST. 什么也是通过POST传递2的好方法。

Things I have thought of 我想到的事情

  • Adding the GET request to a hidden field? 将GET请求添加到隐藏字段?

     <input type="hidden" id="trip" value="{{ $trip->id }}" /> 
  • Trying to get the current GET parameter with jQuery or javascript? 尝试使用jQuery或javascript获取当前的GET参数?

This is the code of my POST with Ajax 这是我的Ajax POST代码

$.ajax({
        type: "POST",
        url: "markers/add",
        data: {"lat": lat, "lng": lng},
        success: function(success) {
            if(success) marker.setMap(null);
        }
    });

And In my PHP I should have the trip_id also 在我的PHP中,我也应该有trip_id

    $marker->lat = Input::get('lat');
    $marker->lng = Input::get('lng');
    $marker->trip_id = Input::get('trip');

Thank you! 谢谢!

I would suggest taking the approach of adding it as a hidden form input. 我建议采取将其添加为隐藏表单输入的方法。 As far as I know there's no 'best practice' guideline that discourages this, and prevents you from having to write/maintain extra javascript just to add that value to the POST data. 据我所知,没有“最佳实践”指南会阻止这样做,并防止您仅为了将该值添加到POST数据而编写/维护额外的JavaScript。

<pedantic> Strictly speaking though, that's not a GET parameter. <pedantic>严格来说,这不是GET参数。 If it were, the URL would look more like this: 如果是这样,则URL看起来更像这样:

site.com/project?project=2

As it is, it's just another segment of the URL. 实际上,它只是URL的另一段。 </pedantic>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM