Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Atahualpa 3 Wordpress theme (http://forum.bytesforall.com/forumdisplay.php?f=2)
-   -   Using ajax code in "Pages" pages. (http://forum.bytesforall.com/showthread.php?t=2596)

gnucom Jul 22, 2009 08:23 PM

Using ajax code in "Pages" pages.
 
Hi all, first time posting so forgive any mistakes on this post.

I'm trying to run a very simple ajax application on one of my pages. The application works if placed in its own HTML file, but fails when included in the WP pages editor. Any tips or methods of debugging would be appreciated.

Here is the code, again, very simple:

<script language="Javascript">
function xmlhttpPost(strURL) {
var xmlHttpReq = false;
var self = this;
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
updatepage(self.xmlHttpReq.responseText);
}
}
self.xmlHttpReq.send(getquerystring());
}

function getquerystring() {
var form = document.forms['f1'];
var word = form.word.value;
qstr = 'w=' + escape(word); // NOTE: no '?' before querystring
return qstr;
}

function updatepage(str){
document.getElementById("result").innerHTML = str;
}
</script>

<form name="f1">
<p>word: <input name="word" type="text">
<input value="Go" type="button" onclick='JavaScript:xmlhttpPost("../cgi-bin/simple-ajax-example.cgi")'></p>
<div id="result"></div>
</form>

The CGI script:

#!/usr/local/bin/perl -w
use CGI;
$query = new CGI;
$secretword = $query->param('w');
$remotehost = $query->remote_host();
print $query->header;
print "<p>The secret word is <b>$secretword</b> and your IP is <b>$remotehost</b>.</p>";

Again, all I'm doing is pasting the AJAX code into the WP page editor. Feel free to see the form here: http://gnucom.cc/blog/?page_id=161 .

Flynn Jul 23, 2009 09:23 AM

WP is most likely stripping parts of the code and replacing characters. You can put PHP code in various places in the Atahualpa theme options such as Style & Edit CENTER COLUMN -> ...
but using perl inside a PHP app like Wordpress will be tough, for instance the pages will not even be parsed for Perl unless you have a sophisticated web server setup. I'd try to get that script, or translate it to, PHP

Or try wrapping it into PHP. Leave the CGI/perl part on an external page that the web server parses for Perl, and in Atahualpa use

<?php virtual ("/path/to/script.cgi"); ?>

http://www.php.net/virtual

gnucom Jul 24, 2009 01:33 PM

Thank you, that method almost worked (the server doesn't have the virtual() function for me to use) but it did lead me to something that worked. I'll update you with the post on my exact procedure when I finish writing it!

Again thank you!

P.S. I took the original experiment down so that link I provided won't show the relevant example any longer.

gnucom Aug 1, 2009 07:18 PM

Alright everyone - if anybody followed this link I finally got that tutorial I promised done. Feel free to visit it here: http://blog.gnucom.cc/2009/simple-aj...-in-wordpress/


All times are GMT -6. The time now is 02:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.