2015-10-18 71 views
0

我試圖在myewellness.com添加成員HTTP 405 API jQuery的AJAX PHP

我使用一個WordPress網站jQuery和PHP的,我已經收集用戶的詳細信息,並添加他myewellness.com 這是鏈接到他們的API文檔: http://www.mediafire.com/view/pr6s7isht9ihdao/API-Services-Documentation-v2.0-1.pdf

,但我得到這個對鉻:

OPTIONS https://api.myewellness.com/api/v1/services/membership/create send @ jquery.js?ver=1.11.2 
(index):1 XMLHttpRequest cannot load https://api.myewellness.com/api/v1/services/membership/create. Response for preflight has invalid HTTP status code 405 
(index):1509 Failed: [object Object] 

和CORS未啓用錯誤的火狐狸,

這裏是我的JS:

jQuery.noConflict(); 
    (function($) { 
     $(function() { 
     $("#register_form").submit(function(){ 
      console.log("Wellness API Initiated!"); 

      var api_user_name = $("#user_name").val(); 
      var api_user_email = $("#user_email").val(); 
      var api_payment_first_name = $("#payment_first_name"); 
      var api_payment_last_name = $("#payment_last_name"); 
      var api_user_password = $("#user_password").val(); 
      var api_client_address_one = $("#client_address_one").val(); 
      var api_client_address_two = $("#client_address_two").val(); 
      var api_client_city = $("#client_city").val(); 
      var api_client_state = $("#client_state").val(); 
      var api_client_zip = $("#client_zip").val(); 
      var api_client_gender = $("#client_gender").val(); 
      var api_client_home_phone = $("#client_home_phone").val(); 
      var api_client_cell_phone = $("#client_cell_phone").val(); 
      var api_client_work_phone = $("#client_work_phone").val(); 
      var api_client_birth_date = $("#client_birth_date").val(); 

      $.ajax({ 
       type: "POST", 
       url: "https://api.MYEWELLNESS.com/api/v1/services/membership/create", 
       /*headers: { 
        'Authorization':'Basic Vml0YWxhbGVydA==:MTI5OTky', 
        'Content-Type':'application/json' 
       },*/ 
       data: "user_name="+api_user_name+"&password="+api_user_password+"&first_name="+api_payment_first_name+"&last_name="+api_payment_last_name+"&address1="+api_client_address_one+"&address2="+api_client_address_two+"&city="+api_client_city+"&state="+api_client_state+"&country=US&zip="+api_client_zip+"&email="+api_user_email+"&phone="+api_client_home_phone+"&work_phone="+api_client_work_phone+"&cell_phone="+api_client_cell_phone+"&gender="+api_client_gender+"&birthdate="+api_client_birth_date, 
       datatype: "json", 
       beforeSend: function(xhr) { xhr.setRequestHeader("Authorization", "Basic " +"Vml0YWxhbGVydA==:MTI5OTky"); }, 
       success: function(msg){ 
        console.log("Success: "+msg); 
       }, 
       error: function(error){ 
        console.log("Failed: "+error); 
       } 
      }); 
      console.log("API Fire Complete!"); 
      return false; 
     }); 
     }); 
    })(jQuery); 

回答

1

他們的服務器是不是給你權限去通知其他人的瀏覽器來訪問他們的API。

你不應該想這樣做,反正 - 否則你就會成爲你的API密鑰交給所有的訪問者!

從你的服務器充分利用API請求,使用PHP,來代替。你可能會想看看cURL library這樣做。

+0

但是當我刪除標題,API服務器說未經授權,我不能只使用JS來算出這個? –

+0

不,你不能。使用PHP。 – Quentin

+0

請你能指導我怎麼做? –