AJAX转换相对路径与codeigniter绝对路径 [英] Convert ajax relative paths to absolute paths with codeigniter

查看:271
本文介绍了AJAX转换相对路径与codeigniter绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正与codeigniter和jQuery阿贾克斯。我有一些incosistencies黑/白我的应用程序在本地WAMP(正常使用)和我已部署的应用程序(没有这么多)。一旦有可能提出的解决办法是阿贾克斯相对路径转换为阿贾克斯绝对路径,所以它看起来像:

I am working with codeigniter and jquery ajax. I'm having some incosistencies b/w my app locally on wamp (working perfectly) and my deployed app (not so much). Once possible suggested fix is to convert ajax relative paths to absolute paths for ajax, so it looks like:

url: "YOURBASEPATH/AjaxController/update",
location.href = "YOURBASEPATH/pan_controller/my_detail";

下面是我的code现在:

Here's my code right now:

$.ajax({a
               type: "POST",
               url: "AjaxController/update",
               data:{ i : searchIDs, m : message },                        
               dataType: 'json',
               .done(function() { 
                    alert("REFRESHING..");
                    location.href = "pan_controller/my_detail";
                });
              }
           })

我一直在使用的https://philsturgeon.uk/blog/2009/09/Asset-handling-in-$c$cIgniter-with-the-BASE-tag一段时间。这是同样的事情,具有基本URL硬codeD吗?如果不是我应该怎么做这里没有搞乱其他路线,并部署的能力,这是相对的路线的优势。

I have been using https://philsturgeon.uk/blog/2009/09/Asset-handling-in-CodeIgniter-with-the-BASE-tag for some time. Is this the same thing as having the base url hardcoded in ? if not how should I do this here without messing up other routes and the ability to deploy which are the advantage of relative routes.

推荐答案

在你的标题部分只需添加下面的脚本。

In your header section just add the following script.

<script type="text/javascript">
    var BASE_URL = "<?php echo base_url();?>";
</script>

然后在你的Ajax code使用 BASE_URL 作为一个变量。意思是:

Then in your Ajax code use BASE_URL as a variable. Means:

网​​址:BASE_URL +AjaxController /更新, location.href = BASE_URL +pan_controller / my_detail;

url: BASE_URL+"AjaxController/update", location.href = BASE_URL+"pan_controller/my_detail";

$.ajax({a
               type: "POST",
               url: BASE_URL+"AjaxController/update",
               data:{ i : searchIDs, m : message },                        
               dataType: 'json',
               .done(function() { 
                    alert("REFRESHING..");
                    location.href = BASE_URL+"pan_controller/my_detail";
                });
              }
           })

很简单的解决方案。

Very simple solution.

这篇关于AJAX转换相对路径与codeigniter绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆