妄徒之命 2015-10-18 19:52 采纳率: 100%
浏览 34

HTTP 405 API jQuery Ajax PHP

i am trying to add member on myewellness.com

i am using jquery and php on a wordpress website, i have to collect the user's details and add him to myewellness.com this is the link to their api documentation: http://www.mediafire.com/view/pr6s7isht9ihdao/API-Services-Documentation-v2.0-1.pdf

but i am getting this on chrome:

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]

and CORS not enabled error on fire fox,

here is my 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条回答 默认 最新

  • weixin_33713350 2015-10-19 15:29
    关注

    Their server isn't giving you permission to instruct other people's browsers to access their API.

    You shouldn't want to do that anyway - otherwise you will be handing over your API key to all your visitors!

    Make the API requests from your server, using PHP, instead. You'll probably want to look at the cURL library to do that.

    评论

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名