douaoli5328 2015-02-06 15:08
浏览 37
已采纳

Wordpress上的JSON API - 创建帖子

I try to create a form on my website where a visitor will be able to make a post in a specific category. The problem is that I get a 404 page not found error. Here is my code:

echo "<textarea cols='50' rows='10' style='font-size: 24px;'></textarea><br><br>";
echo "<button id='sendmessage' style='padding:10px'>Submit</button>";

echo "<script>
    jQuery('#sendmessage').click(function(e){
        e.preventDefault();
        jQuery.ajax({
        // get the nonce
        dataType: 'jsonp',
        url: '/api/get_nonce/?controller=posts&method=create_post',
        type: 'GET',
        success: function  (data) {
            // create the post
            jQuery.ajax({
                url: '/api/create_post/',
                type: 'POST',
                dataType: 'jsonp',
                data: {nonce: data.nonce, status:'publish', categories:'mycategory', title:'xxxx', content:'xxxx'},
                success: function  (data) {

                },
                error: function  (data) {
                    console.log('error');
                }
            });
        },
        error: function  (data) {
            console.log('error');
        }
        });
    });
    </script>"

On the console, I get this error:

"NetworkError: 404 Not Found - http://localhost/api/get_nonce/?controller=posts&method=create_post&callback=jQuery111109654319724222027_1423235015042&_=1423235015043"

I am working on localhost right now.

  • 写回答

3条回答 默认 最新

  • dongxun3424 2015-02-06 15:13
    关注

    For those URL's to work you should enable user-friendly permalinks. Else you should use ?json=get_nonce&controller=posts&method=create_post

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据