Re: [extend]enable xajax upload files(for xajax 0.2.4)
I guess I had apache down for a while longer ...
This link should be good again (minus the changes above) ... working on making this 0.5 compliant
xajax PHP Class Library - The easiest way to develop asynchronous Ajax applications with PHP
You are not logged in. Please login or register.
I guess I had apache down for a while longer ...
This link should be good again (minus the changes above) ... working on making this 0.5 compliant
Edit: sorry, I noticed later IE pops up a window to download the content of the iframe this way - the XML response. :-(
I modified the code a bit and it seems it is working now, changed only the JS file.
* @base upon RainChen @ Fri Jul 28 17:06:37 CST 2006 version 0.1 for xajax 0.2.4
* @author Oliver Trebes @ Sat Feb 24 11:49:53 CET 2007
* @uses xajax file upload extend
* @access public
* @param null
* @return null
* @version 0.2
*/
function xajax_extend()
{
if(typeof(xajax) == 'undefined')
{
return false;
}
xajax.newSessionID = function()
{
var sessionID;
sessionID = new String(new Date().getTime());
var random = new String(Math.random( )).substr(2);
sessionID = sessionID + random;
return sessionID;
}
xajax.setStatusMessages = function(msg)
{
window.status = msg;
}
var loadingTimeout;
xajax.upload = function(rpcFunc,formID,url)
{
var form = xajax.$(formID);
if(!form)
{
return false;
}
var newSessionID = xajax.newSessionID();
// init status
if (document.body && xajax.config.waitCursor)
document.body.style.cursor = 'wait';
clearTimeout(loadingTimeout);
//loadingTimeout = setTimeout("xajax.loadingFunction();",400);
if(!url)
{
url = xajax.config.requestURI;
}
var separator = '?';
if(url.indexOf('?') != -1)separator = '&';
url += separator + 'xjxfun='+encodeURIComponent(rpcFunc);
url += "&xjxr=" + new Date().getTime();
// get the upload file local path
var formItem;
var nodeName;
for(var i=0; i<form.getElementsByTagName('input').length; i++)
{
formItem = form.elements[i];
nodeName = new String(formItem.nodeName).toLowerCase();
if(formItem.name == '' || nodeName == 'button')
{
continue;
}
if(formItem.type == 'file')
{
url += '&'+formItem.name+'='+encodeURIComponent(formItem.value);
}
}
form.action = url;
var iframeName = form.id + newSessionID;
var iframe;
if((iframe = xajax.$(iframeName)))
{
document.body.removeChild(iframe);
}
iframe = xajax.createIframe(iframeName,iframeName);
form.target = iframeName;
var xmlDoc;
var responseXML;
var responseOBJ;
if(typeof iframe.onreadystatechange == 'object') // for IE
{
iframe.onreadystatechange = function()
{
if(iframe.readyState == 'complete' && !iframe.loaded)
{
// IE load twice (bug or feature?)
iframe.loaded = true;
xmlDoc = document.frames(iframe.id);
if(xmlDoc.window.document.location != iframe.src)
{
responseOBJ = xajax.tools.getRequestObject();
responseXML = xmlDoc.window.document.XMLDocument;
xajax.uploadResponse(responseXML,iframe, xmlDoc,responseOBJ);
}
}
}
}
else // for FF
{
iframe.onload = function()
{
xmlDoc = iframe.contentWindow;
if(xmlDoc.window.document.location != iframe.src)
{
responseOBJ = xajax.tools.getRequestObject();
responseXML = xmlDoc.document;
xajax.uploadResponse(responseXML,iframe, xmlDoc,responseOBJ);
}
}
}
}
xajax.uploadResponse = function(responseXML,iframeObj, xmlDoc,responseOBJ)
{
xml = responseXML.documentElement;
if (xml == null)
{
return;
}
for (var i=0; i<xml.childNodes.length; i++)
{
if (xml.childNodes[i].nodeName == "cmd")
{
xajax.tools.xml.processFragment(xml.childNodes[i], i, null, responseOBJ);
}
}
xajax.tools.queue.process(xajax.response);
document.body.style.cursor = 'default';
setTimeout("xajax.deleteIframe('"+iframeObj.name+"');",400);
iframeObj = null;
}
xajax.deleteIframe = function(iframeName)
{
if((iframe = xajax.$(iframeName)))
{
document.body.removeChild(iframe);
}
}
xajax.createIframe = function(name,id)
{
var iframe;
if(!id)
{
id = '';
}
if(document.all && navigator.appName == "Microsoft Internet Explorer") // for IE
{
iframe = document.createElement('<iframe id="'+id+'" name="'+name+'">');
}
else // for FF
{
iframe = document.createElement('iframe');
iframe.id = id;
iframe.name = name;
}
iframe.width = '0';
iframe.height = '0';
iframe.style.display = 'none';
iframe.scrolling = 'no';
iframe.src = 'about:blank';
document.body.appendChild(iframe);
return iframe;
}
}
xajax_extend();
Note, I used $xajax->getJavascript("libs/"); to print the javascript, not the usual $xajax->printJavascript("libs/"); since the latter did not include the extended js file.
If anyone it the mood to fix it, I'm curious ;-)
Xajax version was: 0.5rc1
Last edited by joseph (2009-01-12 10:33:30 AM)
I'm unable to upload file using xajax_extended
I have placed test file in below mentioned location as you told
1.xajaxExtend.php (server side script, save to the path as xajax.inc.php)
2.xajax_js/xajax_extend.js (browser side script, save to the path as xajax.js)
3.examples/uploadTest.php (demo(show you how it work), save to the tests path.
http://localhost//xajax_0.2.4/examples/uploadTest.php and it open sample interface with file browser.
I'm getting error like : Element with the id "testForm212520000135350848582812983345" not found
When i checked form ID : testForm212520000135350848582812983345 (Sid) , xajaxWork1251997965121 (this.workID)
Not getting any more response,
Thu Sep 03 2009 23:16:53 GMT+0530 (India Standard Time): Element with the id "testForm212520000135350848582812983345" not found.
Does anyone know how to go about submitting this upload form without using a submit button?
Thanks in advanced
Stalin
Hi all.
Very great hack, but I found some problems.
I use often functions to handle php functions, like this:
and the functions described in this topics doesn't work properly. That's because the js function use "xajax" and "xajaxr" in the GET vars, but the xajax->register use a complex style, using for example "xjxevt" for events, "xjxargs" for arguments and so on and so the objPlugins aren't able to catch the arguments.
For example xajaxFunctionPlugin.inc.php has in it:
The solution is quite symple.
Modify xajax_extend.js as follows
xajax.upload = function(rpcFunc,formID,type,url)
{
[CUT]
if(url.indexOf('?') != -1) separator = '&';
//-- Start Mod by Ptah --//
if (type == 'fun'){
xajaxArgument = 'xjxfun';
} else if(type == 'event'){
xajaxArgument = 'xjxevt';
} else if(type == 'script'){
xajaxArgument = 'xjxGenerateJavascript';
} else if(type == 'style'){
xajaxArgument = 'xjxGenerateStyle';
} else if(type == 'arg'){
xajaxArgument = 'xjxargs';
} else {
xajaxArgument = 'xajax';
}
//-- End Mod by Ptah --//
url += separator + xajaxArgument + '=' + encodeURIComponent(rpcFunc);
url += "&xjxr=" + new Date().getTime();
//-- Start Mod by Ptah --//
url += "&xajax=" + xajaxArgument;
//-- End Mod by Ptah --//
Modify xajaxExtend.php as follows
$xajaxRequest = array();
//-- Start Mod by Ptah --//
$method = @$_GET["xajax"];
$xajaxRequest[$method] = @$_GET[$method];
$xajaxRequest["xjxr"] = @$_GET[$method];
//-- End Mod by Ptah --//
// reset RequestMode
[CUT]
//-- Start Mod by Ptah --//
$xajaxargs = array(get_original_data($_POST));
$xajaxRequest['xajaxargs'] = $xajaxargs;
$_POST = $xajaxRequest;
//-- End Mod by Ptah --//
and then modify the onsubmit event in the form like this:
onsubmit="return xajax.upload('name_of_xajax_function','name_of_form', 'type_of_plugin')"
where type_of_plugin is one of this:
fun for xajaxFunctions
event for xajaxEvents
script for xajaxScripts
style for xajaxStyles
arg for xajaxArguments
"empty" for using in "easy mode"
That's all folks ![]()
(Sorry for my english
)
Posts [ 51 to 54 of 54 ]
Currently used extensions: pun_repository. Copyright © 2008 PunBB
[ Generated in 1.564 seconds, 9 queries executed ]