Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 不允许使用Api 405方法jquery_Javascript_Php_Ajax_Api_Http Status Code 405 - Fatal编程技术网

Javascript 不允许使用Api 405方法jquery

Javascript 不允许使用Api 405方法jquery,javascript,php,ajax,api,http-status-code-405,Javascript,Php,Ajax,Api,Http Status Code 405,我在通过Jquery/Ajax调用API时遇到了问题。。 我得到405错误。。。 谁能帮我修改一下代码,这样我就可以用了。。求你了,我真的需要它 我得到的错误是: 这是我的密码: <script> jQuery.noConflict(); (function( $ ) { $(function() { $("#register_form").submit(function(){ console.log("Welln

我在通过Jquery/Ajax调用API时遇到了问题。。 我得到405错误。。。 谁能帮我修改一下代码,这样我就可以用了。。求你了,我真的需要它

我得到的错误是:

这是我的密码:

<script>
    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").val();
            var api_payment_last_name = $("#payment_last_name").val();
            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();
            //alert(api_payment_first_name +  api_user_name + api_client_zip);
            $.ajax({
                type: "POST",
                url: "https://api.MYEWELLNESS.com/api/v1/services/membership/create",
                headers: {
                    'Authorization':'Basic VitalAlert:5kpN9cYTafnVmZTS',
                    '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);
                    alert("success");
                    alert(data);
                    return flase;
                },
                error: function(error){
                    console.log("Failed: "+error);
                    alert("false");
                    alert(data);

                    return false;
                }
            });


            console.log("API Fire Complete!");
            return false;
        });
      });
    })(jQuery);
</script>

jQuery.noConflict();
(函数($){
$(函数(){
$(“#登记表”)。提交(函数(){
console.log(“健康API启动!”);
var api_user_name=$(“#user_name”).val();
var api_user_email=$(“#user_email”).val();
var api_payment_first_name=$(“#payment_first_name”).val();
var api_payment_last_name=$(“#payment_last_name”).val();
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();
//警报(api\ U支付\首\名+api\用户名+api\客户端\邮编);
$.ajax({
类型:“POST”,
url:“https://api.MYEWELLNESS.com/api/v1/services/membership/create",
标题:{
“授权”:“基本生命:5kpN9cYTafnVmZTS”,
“内容类型”:“应用程序/json”
},
数据:“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_address_-two+”&city=“+api_-client_-city+”&state=“+api_-city+”&state=“+api_-client_-state+”&state=“+api_-state=+api_-state=”+api_客户_家庭电话+”&工作电话=“+api_客户_工作电话+”&手机=“+api_客户_手机+”&性别=“+api_客户_性别+”&出生日期=“+api_客户_出生日期,
数据类型:“json”/*
发送前:函数(xhr){xhr.setRequestHeader(“授权”,“基本”+“Vml0YWxhbGVydA==:MTI5OTky”);}*/
成功:功能(msg){
console.log(“成功:+msg”);
警惕(“成功”);
警报(数据);
回剥;
},
错误:函数(错误){
console.log(“失败:+错误”);
警告(“假”);
警报(数据);
返回false;
}
});
控制台日志(“API火灾完成!”);
返回false;
});
});
})(jQuery);

假设您的授权头是正确的,您可能想试试这个

注意事项:
1) 将数据类型更改为数据类型
2) 从标题中删除“内容类型”:“应用程序/json”
3) 将数据内容替换为以下格式

从步骤1开始测试。如果失败,请继续执行步骤2等

$.ajax({
类型:“POST”,
url:“https://api.MYEWELLNESS.com/api/v1/services/membership/create",
标题:{
“授权”:“基本”+btoa('VitalAlert:5kpN9cYTafnVmZTS')”
},
数据:{
用户名:api用户名,
密码:api_用户_密码,
...
...
},
数据类型:“json”,
成功:功能(msg){
console.log(“成功:+msg”);
警惕(“成功”);
警报(数据);
回剥;
},
错误:函数(错误){
console.log(“失败:+错误”);
警告(“假”);
警报(数据);
返回false;
}

});通过从“CURL”发送请求和数据来解决此问题。。 Ajax/Json在发送查询时阻止了请求。。 所以我将代码更改为CURL request,它就开始工作了


谢谢大家的帮助。

您使用的是哪个版本的jquery?@smcrohan jquery.js?ver=1.11.2:4请有人帮帮我……(您的代码是
键入:“POST”
,但您的请求中显示了
请求方法:选项
。我会从那里开始查找。如何解决这个问题@smcrohancheck我已经在您的snipet下面添加了更新的代码。请告诉我变量和字符串是否编写正确??我只是询问数据中的内容。字符串将像我添加的一样添加。告诉我内容t…@vincentstyheaders:{'Authorization':'Basic'+btoa('VitalAlert:5kpN9cYTafnVmZTS')},头运行良好,但这是我面临的跨域问题…现在我得到的错误是找不到405方法..这很可能是跨域问题