-2

I am working with wordpress xmlrpc javascript api, a neat javascript api for accessing wordpress's xmlrpc api from javascript.

The problem I have is, after wp.editPost returns true, the post content is simply blank!

This is my relevant code:

var wp = new WordPress(blog, username, password);
var blogId = 1;
var object = wp.getPost(blogId, postId);
// alert(JSON.stringify(object));
var currentContent = object.post_content;
alert(currentContent); // works fine
var newContent = currentContent.replace('</ul>', strToInsert + '</ul>')
alert(newContent); // works, and it is what I want the content to be after editing
object = wp.editPost(blogId, postId, {post_content:newContent});
alert(JSON.stringify(object)); // works, alerts true

Now, refreshing my page, the changes do not take place, but instead my content becomes empty now.

empty content

Any idea what is wrong? I am sure it has to be something with wordpress. I could look into it but I was wondering if any of you had similar problem too!

Note: I refresh the page while I was logged in. Does this matter anyhow?

Prasanth
  • 5,230
  • 2
  • 29
  • 61

1 Answers1

0

Well, the problem, was with newContent. It was html, and wordpress didn't like it. I solved it after numerous attempts by escaping newContent before it is sent, using this SO answer's code. And, it works now.

Thanks to @Anentropic.

Community
  • 1
  • 1
Prasanth
  • 5,230
  • 2
  • 29
  • 61