dougang5993 2014-10-30 12:35
浏览 103
已采纳

使用jquery .load()函数获取包含句点('。')的参数的404错误

I'm trying to call a controller function using the .load() function but I'm getting an error probably because of the '.' encoding. I'm doing the call like this:

$("#main-content").load(
   url + "/" + encodeURIComponent(text1) + "/" + encodeURIComponent(text2)
);

Everything goes fine except when text1 ends with a period:

var text1 = 'This causes error.';

The url is encoded like:

http://localhost/index.php/controller/function/This%20causes%20error./Text2

And I'm getting a 404 error in the Chrome console, so I suspect that the '.' is breaking the URL.

I've been looking a lot of posts like this or this, but those solutions doesn't work for me. I'm thinking into create a function that converts the '.' into any other character and then do the opposite in the server, but I prefer to look for something more "elegant" first.

Any ideas? Thanks

  • 写回答

1条回答 默认 最新

  • dow98764 2014-10-30 21:00
    关注

    Try using ajax post method

      $.ajax({
            url: url+ + "/",
            type: 'POST',
    
            data: {data1:encodeURIComponent(text1),data2:encodeURIComponent(text2)},
    
            success: function (data, status)
            {
                   $("#main-content").text(data)
    
            }
        });
    });
    

    Receive text1 and text2 at your controller as

     $text1=$this->input->post("data1")  
     $text1=$this->input->post("data2")  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分