illidan 发表于 2013-1-1 15:44:33

js中$ajax({})想调用php的路径问题

我现在的情况是想把原来代码用CI重构,

遇到一个问题,原来的js代码里

htmlobj = $.ajax({
    type : "post",
    url : "../php/add_comment.php",
    data : {
   'article_id' : article_id,
   'user_id' : user_id,
    },
    async : false
   });

标红色地方的路径现在找不着了,但是我的目录结构里是有这个目录和文件的。
求助应该怎么改?

傲罗 发表于 2013-1-1 21:07:36

site_url('php/add_comme');

273579540 发表于 2013-1-2 00:19:10

<base href="<?=base_url()?>"/>

illidan 发表于 2013-1-3 15:20:51

傲罗 发表于 2013-1-1 21:07 static/image/common/back.gif
site_url('php/add_comme');

你写的这种好像只能在PHP里嵌入script的时候用

illidan 发表于 2013-1-3 15:21:07

273579540 发表于 2013-1-2 00:19 static/image/common/back.gif


恩,用你说的方法可以

yunnysunny 发表于 2013-1-4 12:59:34

在head里面制定base标签,然后js里面写相对路径就可以了。
http://codeigniter.org.cn/forums/thread-13219-1-1.html

illidan 发表于 2013-1-4 17:34:53

yunnysunny 发表于 2013-1-4 12:59 static/image/common/back.gif
在head里面制定base标签,然后js里面写相对路径就可以了。
http://codeigniter.org.cn/forums/thread-13219 ...

恩,谢谢,你贡献的项目我有时间见再看看。

ichou 发表于 2013-1-5 00:28:50

如果你用了url_helper
http://codeigniter.org.cn/user_guide/helpers/url_helper.html

如果没用,那么你就从了它吧

ichou 发表于 2013-1-5 00:34:30

另外 3L的方法也可以
不过总觉得要用这个标签得慎重考虑{:soso_e141:}

illidan 发表于 2013-1-5 13:02:29

ichou 发表于 2013-1-5 00:28 static/image/common/back.gif
如果你用了url_helper
http://codeigniter.org.cn/user_guide/helpers/url_helper.html



这些函数好像只能用到Php里内嵌的js里,在单独的js文件里,我不知道怎么使用,求解
页: [1] 2
查看完整版本: js中$ajax({})想调用php的路径问题