Home  >  Article  >  Backend Development  >  javascript - jquery ajax程序问题

javascript - jquery ajax程序问题

WBOY
WBOYOriginal
2016-06-06 20:42:35865browse

<code>$(function(){
    $.post("{:u('Index/ajax_load_cartNum')}",function(msg)
    {   
        var oGoodsNum = document.getElementById('cartGoodsNum');
        if(msg.flag)
        {
            oGoodsNum.innerHTML = msg.cartGoodsNum;

        }
        else
        {

            oGoodsNum.innerHTML = 0;
        }    

    },'json')


});
</code>

这个ajax程序我放在HTML页面就没问题(Url:http://www.lanxiang.com/Index/ajax_load_cartNum.html),
但是一旦单独出来js文件
ajax的请求的URL路径就会多出来一个Public目录(Url:http://www.lanxiang.com/Public/%7B:u('Index/ajax_load_cartNum')%7D),页面里面有 这个标签

回复内容:

<code>$(function(){
    $.post("{:u('Index/ajax_load_cartNum')}",function(msg)
    {   
        var oGoodsNum = document.getElementById('cartGoodsNum');
        if(msg.flag)
        {
            oGoodsNum.innerHTML = msg.cartGoodsNum;

        }
        else
        {

            oGoodsNum.innerHTML = 0;
        }    

    },'json')


});
</code>

这个ajax程序我放在HTML页面就没问题(Url:http://www.lanxiang.com/Index/ajax_load_cartNum.html),
但是一旦单独出来js文件
ajax的请求的URL路径就会多出来一个Public目录(Url:http://www.lanxiang.com/Public/%7B:u('Index/ajax_load_cartNum')%7D),页面里面有 这个标签

个人猜测,{:u}标签从php文件中拿出,没有被解析。

编程问题 + js文件不能解析php,只能放在php中
decodeURI("http://www.lanxiang.com/Public/%7B:u('Index/ajax_load_cartNum')%7D")
"http://www.lanxiang.com/Public/{:u('Index/ajax_load_cartNum')}"

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn