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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度