WRT: How to post to your WordPress using Ajax (+code)

July 1, 2010
By Bogomil Shopov
Post Image

I just finished my “share2” WRT (Web Runtime Toolkit) widget. It allows me to post quick messages to my WordpPress blog or to any blog that uses MetaWeblog API.

Here are some key parts from the script:

Ajax function that sends the requests and gets the result

function ajExec(url, param, callback, isXML) {
    var req = new XMLHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4 && req.status == 200) {
            if(!isXML && req.responseText != null)
            else if(isXML && req.responseXML != null)
        } else if (req.readyState == 4 && req.status != 200) {

            var err = "Error: "+req.status;
        req.open("POST", url, true);
        req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");


Let’s click on Publish button

function sendButtonClicked(event) {
     saved_username = widget.preferenceForKey("username");
	 saved_pass = widget.preferenceForKey("pass_s");
	 saved_tags = widget.preferenceForKey("tag");
	 saved_server = widget.preferenceForKey("server");
	 pub = blogField.getText();

	ajExec(saved_server,'metaWeblog.newPostMyBlog'+saved_username+''+saved_pass+'titleThis is a postdescription'+pub+'1',showAnswer,1);

The milestone was to find correct XML structure for the query, because the examples from WordPress website and other websites are all wrong. Please see the XML and it’s structure

Download this script

You can download the application and see how works from here..

Run it

The logo:

The Settings screen:

If you want to run it into your Symbian device – rename it to share2.wgz and upload it to your device. The Symbian will do the rest. Tested on Nokia N95.

Bogomil Shopov

I care about privacy, ethical design, and freedom in many aspects. I spend 20+ years working as a web developer and architect, analyst, manager, and product owner/manager in different environments, several countries, and multiple software industries like Healthcare and Hospitality. I wore many hats, and I use the knowledge gathered to optimize the flow of value across complex systems.

Leave a reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.