New Zenner
- Join Date:
- Feb 2009
- Posts:
- 33
- Plugin Contributions:
- 0
jQuery to Ajax: how to call application_top.php?
Hi everyone,
I'm using jQuery on a website I'm developping locally, and I'm now looking to integrate this plugin, which basically takes any link and turns it into an AJAX link.
While I have my jQuery files located in my custom template's jscript folder, I'm wondering how I can call application_top.php with this plugin. Coz for now, sure enough, when the content DIV is "refreshed" I get an empty DIV... :cry:
Maybe I can explain how it works a little...
Below is
<head>
<script type="text/javascript" src="includes/templates/CUSTOM_TEMPLATE/jscript/jscript_jquery.min.js"></script>
<script type="text/javascript" src="includes/templates/CUSTOM_TEMPLATE/jscript/jscript_jquery.toAJAX.min.js"></script>
<script type="text/javascript">
$(function(){
$("#navigation a").toAJAX();
});
</script>
</head>
<body>
<ul id="navigation">
<li><a rel="dynamicContent" href="/home">home</a></li>
<li><a rel="dynamicContent" href="/about">about</a></li>
</ul>
<div id="dynamicContent">
<!-- dynamic content goes here, basically div.centerColumn, etc. -->
</div>
</body>
I have seen other AJAX modules for ZC using a folder placed at the root, which contains a php file calling the application_top:
<?php
require('../includes/configure.php');
ini_set('include_path', DIR_FS_CATALOG . PATH_SEPARATOR . ini_get('include_path'));
chdir(DIR_FS_CATALOG);
require_once('includes/application_top.php');
?>
But not sure how to proceed for this plugin.
Below is the plugin code:
/*
* Copyright (C) 2009 Jonathan Azoff <[email protected]>
*
* This script is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
// toAJAX v1.0.1 - A script that can be used to turn any page into an AJAX page
// Usage: call $("selector").toAJAX() on any link to turn it into an AJAX link. The links you
// use toAJAX on must have a rel attribute defined so that the AJAX handler knows what
// to look for on the AJAX call.
// Arguments: The toAJAX function currently only takes 1 argument, whch is a callback function
// Returns: A jQuery object that represents the selected toAJAX links
// Notes: toAJAX works best with sites that already work without AJAX and only have content that
// changes in a distinct area or areas.
;(function($) {
// Preloader Image
var preloader = $("<img/>").attr("alt", "loading...").attr("src", "images/preloader.gif");
// XHR Object
var xhr = null;
// The toAJAX extension
$.fn.toAJAX = function(callback)
{
// The actual worker routine, it does all of the AJAX stuff
var handler = function()
{
var obj = $(this);
var url = obj.attr("href") || obj.attr("src");
var id = "#" + obj.attr("rel");
var target = $(id);
// if we have an id to load into and a link where we want the information from...
if(url && id != "#" && xhr == null)
{
xhr = $.ajax({
type: "GET",
url: url,
cache: false,
complete: function(){
if(callback) callback();
xhr = null;
},
beforeSend: function(){
target.empty().append(preloader);
},
error: function(){
throw("toAJAX could not complete, an AJAX error ocurred.");
},
dataFilter: function(data){
return $(data).filter(id).html();
},
success: function(data){
target.html(data);
}
});
}
// make sure the link does not load
return false;
}
return this.click(handler).keypress(handler);
}
})(jQuery);
Well, any help will be much welcome!!! :hug: