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.


 
Prev Previous Post   Next Post Next
  #1  
Old Jul 22, 2009, 08:23 PM
gnucom
 
3 posts · Jul 2009
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 .
 

Bookmarks



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 06:34 PM.


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