laravel ajax url,php - Laravel 5.1 ajax url parameter is url - Stack Overflow

I am working with Laravel 5.1 for the first time and I cannot understand why I am getting 404s on an ajax call that passes a URL to the server PHP script as a parameter.

I am executing an Ajax call that is being handled by a route as follows:

Route::get('ajax/{act}', ['uses' => 'AjaxController@helpers', 'as' => 'ajax.helpers']);

I want the variable {act} to hold the sring of key / value pairs I pass. I decode these in the PHP at the server end. The Ajax PHP script contains a variety of helpers and I do not want to create a Laravel rout for each.

In my app, the user will input a url in a form field, which I capture in a variable called website

My ajax call needs to accept:

var url = '/ajax/act=url&u=' + website;

I am doing this to build the url I then pass to a jQuery $.getJSON call:

var url = '/ajax/act=url&&u=' + encodeURIComponent(website);

I would expect the encodeURIcompponent() function to make this work, but it returns 404 when any of the parameters contain / characters prior to the encodeURIComponent(). My base url works perfectly without the additional url as a parameter.

But passing a url as a variable value, it throws 404.

This is what the url in ajax call looks like that returns 404:

http://my.app/ajax/act=url&u=http%3A%2F%2Fgoogle.com

This url works perfectly (I have removed the // from http://google.com:

http://my.app/ajax/act=url&u=http%3Agoogle.com

It also fails when there is additional path items in the variable url as it contains additional / characters, like as follows:

http://google.com/subfolder

How do I pass the full url as a parameter in the ajax call? Thanks!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值