【问题标题】:How parse URL contain # in AjaxAjax中如何解析URL包含#
【发布时间】:2011-05-25 14:58:49
【问题描述】:

我想用 Google 可抓取的 ajax 更改我的网站。

使用网址: Http://mysite/artices/view/#!/1234 我如何在上面的 URL 中获得 1234

【问题讨论】:

标签: php ajax url


【解决方案1】:

我想你要的是正则表达式,所以我给你一个:

/#!\/(\d+)/

第一个(也是唯一一个)反向引用是您想要的数字。

【讨论】:

    【解决方案2】:

    嗨,你不能在“#”之后向服务器发送字符串,这是你可以做到的,我已经为你创建了完整的工作示例:

    <?php
        if($_POST['hello'])
        {
            print_r($_POST);
           echo '<br>';
           echo $_SERVER['REQUEST_URI'] . '<br>';        
            die();
        }
    
    ?>
    <html>
        <head>
            <script type="text/javascript" language="javascript" src="jquery.js" ></script>
            <script type="text/javascript" language="javascript">
                $(document).ready(function() {
                    $('#look').click(function()
                    {
                        var url = 'http://localhost/tests/form.php#cool=1';
                        var paramAfter = url.split('#')[1];
    
                        $.post('http://localhost/tests/form.php#cool=1', "hello=1&paramAfter=" + encodeURIComponent(paramAfter), function(data)
                        {
                            $('#content').html(data);
                        });
                        return false;
                    });
                });
            </script>
        </head>
        <body>
            <a href="#" id="look">Click me</a>
            <div id="content">
                No content
            </div>
        </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2011-05-18
      • 2014-05-07
      • 2013-04-16
      • 2016-08-02
      • 1970-01-01
      • 1970-01-01
      • 2018-12-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多