Wordpress Themes - WP Forum at BFA
There will be no more development for Atahualpa (or any other theme), and no support. Also no new registrations. I turned off the donation system. I may turn the forum to read only if it gets abused for spam. Unfortunately I have no time for the forum or the themes. Thanks a lot to the people who helped in all these years, especially Larry and of course: Paul. Take care and stay healthy -- Flynn, Atahualpa developer, Sep 2021

Wordpress Themes - WP Forum at BFA » WordPress Themes » Atahualpa 3 Wordpress theme »

Using ajax code in "Pages" pages.


  #1  
Old Jul 22, 2009, 08:23 PM
gnucom
 
3 posts · Jul 2009
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 .
  #2  
Old Jul 23, 2009, 09:23 AM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
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
  #3  
Old Jul 24, 2009, 01:33 PM
gnucom
 
3 posts · Jul 2009
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.
  #4  
Old Aug 1, 2009, 07:18 PM
gnucom
 
3 posts · Jul 2009
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/

Last edited by gnucom; Jul 23, 2010 at 07:35 PM. Reason: Updating links to site.

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to post on 2 seperate "Pages" or "Cats" TPR Atahualpa 3 Wordpress theme 18 Aug 4, 2010 08:24 PM
[SOLVED] Pages - jump - depending if they fit into length of browser window o coop42 Excerpts, Read more, Pagination 4 Nov 15, 2009 02:25 AM
How do you make a right side bar on "Page" pages present different content nasu Sidebars & Widgets 4 May 25, 2009 07:11 PM
where can I rename "categories" and "Pages" into other titling? curious Atahualpa 3 Wordpress theme 5 Apr 28, 2009 03:15 PM
Problems with text "Justify". Layout of Pages too long. Tigger Atahualpa 3 Wordpress theme 2 Mar 28, 2009 05:41 PM


All times are GMT -6. The time now is 11:55 AM.


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