2015-02-06 63 views
0

我嘗試在我的網站上創建一個表單,訪問者將能夠在特定類別中發表帖子。問題是我得到一個404頁面未找到錯誤。這裏是我的代碼:Wordpress上的JSON API - 創建一個職位

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>" 

在控制檯上,我得到這個錯誤:

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

我在localhost上的工作現在。

回答

0

對於那些URL的工作,你應該啓用用戶友好的永久鏈接。否則,你應該使用JSON = get_nonce &控制器=職位&方法= create_post

+0

現在我有200個確定發送郵件,但郵件不存在。 – Tasos 2015-02-06 15:19:27

0

你的代碼工作正常,我改變了狀態起草 數據:{現時:data.nonce,狀態:「草稿」,類別:」 mycategory」,標題: 'XXXX',內容: 'XXXX'},

相關問題