我正在尝试使用PJAX在运行时编写一个内容加载到div的站点.我用PJAX请求的PHP文件都包含页眉和页脚,只生成内容ifisset($_SERVER['X-PJAX'])
但是,当我使用PJAX加载PHP文件时,整个页面都会刷新.我认为我的PJAX代码有问题,但加载纯HTML文件可以正常工作.
编辑:如果它有帮助,我目前正在运行在localhost上的WAMP Server 2.2上运行所有这些.这就是我所做的所有开发工作.
作为参考,这里是我用来加载内容的JS,以及一个php页面的例子
JS:
if ( $.support.pjax ) {
//disable <a> tabs, store value of href so pjax can use it
$('header a').each(function () {
$(this)
.attr('pjax', $(this).attr('href'))
.removeAttr('href')
.css('cursor','pointer')
})
//link up the pjax
.live('click', function () {
var link = $(this)
$('#content').animate({opacity:0}, {duration:500, complete:function(){
$.pjax({
url: link.attr('pjax'),
container: '#content',
complete: function() {
$('#content').animate({opacity:1}, 500);
}
});
}});
});
}
Run Code Online (Sandbox Code Playgroud)
PHP:
//header.php
<?php
//If we are loading with pjax, ignore the header
if (!isset($_SERVER['X-PJAX'])) …Run Code Online (Sandbox Code Playgroud) Pjax标题在我的Rails 3.2.3应用程序中不起作用.其他一切都很好.
这是我的application.html.haml中的标题标签:
%title= content_for?(:title) ? yield(:title) : SITE_NAME
Run Code Online (Sandbox Code Playgroud)
我已经验证了确实content_for(:title)通过在pjax加载的部分中呈现它(并且如果重新加载整个页面它可以正常工作).有任何想法吗?
谢谢!
我如何,只有重装网格视图上的变化在Yii2下拉的事件?
我知道它可以通过pjax完成但不确定在何处以及如何使用代码.
我正在使用Ajax请求与控制器进行通信.这是ajax代码: -
function loadGrid(level) {
alert(level);
$.ajax({
type: 'GET',
url: 'index.php?r=villagedata/level',
data: {level:level},
success: function(data)
{
alert("Success");
$.pjax({container: '#myview'});
}
});
}
Run Code Online (Sandbox Code Playgroud)
当Ajax请求返回成功消息时,我不想重新加载网格.
谢谢.
我在使用pjax时遇到了麻烦.
我在https://github.com/defunkt/jquery-pjax下载了最新的pjax
然后我编写代码作为演示,但它不起作用.main.html
<!DOCTYPE html>
<html>
<head>
<title>main.html</title>
<script type="text/javascript" src="../js/jquery/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../js/jquery/plugin/jquery.pjax.js"></script>
<script>
$(function(){
$(window.document).pjax('a', '#pjax-container')
});
</script>
</head>
<body>
<h1>My Site</h1>
<div class="container" id="pjax-container">
Go to <a href="MyHtml.html">next page</a>.
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
和MyHtml.html如下
<!DOCTYPE html>
<html lang="en">
<head>
<title>MyHtml.html</title>
</head>
<body>
This is my HTML page. <br>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我点击链接时,它直接转发到MyHtml.html.我的代码有什么问题吗?
我可以确定pjax有效,当我点击main.html的后退按钮时,它回到我在main.html之前使用的另一个页面.
我刚刚切换到TemplateResponse使用pjax.它现在可以正确呈现布局,但内容根本不会呈现.即使django-pjax禁用.我的观点代码:
def product(request, slug):
product = get_object_or_404(Product, slug=slug)
return TemplateResponse(request, "layouts/base.html", ({ 'product':product, 'url':request.get_full_path }))
Run Code Online (Sandbox Code Playgroud)
在我的布局中我有这个块:
{% block content %}{% endblock %}
Run Code Online (Sandbox Code Playgroud)
和我的模板:
{% extends "layouts/base.html" %}
{% block content %}
...
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
使用正常的render-shortcutdjango提供,它立即工作.任何建议?提前致谢!
根据这个railscast,我试图让我的rails应用程序上的rack-pjax工作,但我注意到没有变化,也没有任何错误.以下是相关文件:
的Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.13'
gem 'bootstrap-sass', '2.1'
gem 'simple_form'
gem 'rspec'
gem 'pg'
gem 'koala', '~> 1.7.0rc1'
gem 'rack-pjax'
gem 'jquery-rails'
gem 'fancybox-rails'
group :development, :test do
gem 'sqlite3'
end
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
Run Code Online (Sandbox Code Playgroud)
配置/ application.rb中:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
Bundler.require(*Rails.groups(:assets => %w(development test)))
end
module Prestongunderson
class Application < Rails::Application
config.middleware.use Rack::Pjax
config.encoding = "utf-8"
config.filter_parameters += …Run Code Online (Sandbox Code Playgroud) 在以下网站上遇到Pjax片段的难题:
https://dl.dropboxusercontent.com/u/65752410/map.html
目前,单击导航中的"schedule"和"map"链接将通过Pjax加载页面片段以及一些条件javascript,由requirejs提供.
在"地图"页面上,第一页加载将使用.side-panel正确的类计算每个元素的宽度.但是,后续加载将返回宽度0,尽管在查询宽度时所选元素存在于DOM中.
重现错误:
.side_panel将记录为0.如果在此测试期间保持控制台处于打开状态,您将看到在页面加载时记录了正确的宽度,在第二步中动态加载了计划页面,然后在地图页面中加载.side_panel了DOM中的元素,但是返回宽度为0.
请帮助我.我是铁轨上的红宝石新手.现在我想了解jquery-pjax,pjax-rails,rack-pjax gems之间的差异.并且还想了解pjax的基本启动教程.谢谢.
pjax ×8
jquery ×3
javascript ×2
php ×2
ajax ×1
django ×1
gridview ×1
history.js ×1
requirejs ×1
yii2 ×1