【问题标题】:url not changing when loading views to layout using ajax cakephp?使用ajax cakephp 将视图加载到布局时,url 不会改变?
【发布时间】:2014-01-01 14:48:22
【问题描述】:
 function viewContent(url){
       $.ajax({
             type: "post",  // Request method: post, get
             url: url, // URL to request
             success: function(response) {
                                  document.getElementById("content").innerHTML = response;
                           },
                           error:function (XMLHttpRequest, textStatus, errorThrown) {
                                  alert(textStatus);
                           }
          });
          return false;
}

我正在使用此功能将视图加载到默认布局。

<li><?=$html->link(__('Users',true),'javascript:viewContent("view_users/")');?></li>

我正在从将适当的 url 解析到函数的链接中调用该函数。但是当我点击这些链接时,视图加载没有任何问题,但浏览器 URL 没有改变。

【问题讨论】:

标签: javascript php ajax jquery cakephp


【解决方案1】:

一般来说,ajax 请求中的 URL 不会被修改。

下面的帖子讨论一种方法。

Change url on ajax request

您也可以在下面获得兴趣。

http://diveintohtml5.info/history.html

【讨论】:

  • 我想要做的是保持页眉和页脚静态并加载其他视图而不像本网站那样刷新页面。
【解决方案2】:

你在两天前问了一个问题http://stackoverflow.com/questions/20836660/render-views-to-the-layout-without-refreshing-the-page-cakephp/20837687#20837687

现在这个....

解决您的问题的更好方法是

Step 1: use caching for header & footer. 
Step 2: Do not use ajax to update view content.
Step 3: Use standard redirection for pages in order to maintain your links.

Note: use KISS(Keep it simple stupid) methodology

最后一次问你的问题,这样你就能得到更好的答案!

【讨论】:

  • 页眉页脚如何使用缓存,页眉页脚是默认布局。
  • 请告诉我更多有关您的页眉和页脚文件的信息,例如您是如何创建它们的,例如您正在使用一些繁重的查询来创建它们,或者它们只是 html 文件?并尽可能说明您的完整问题。
猜你喜欢
  • 2018-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-15
  • 2012-02-01
  • 1970-01-01
相关资源
最近更新 更多