簡體   English   中英

無法在 SAP UI5 中使用 AJAX 進行 POST 用於非 OData 靜態服務

[英]Unable to do POST using AJAX in SAP UI5 for non-odata restful service

我正在嘗試使用 AJAX 進行 POST 請求,但無法發布。 我收到 401 Unauthorized 錯誤並在請求“電子郵件:[“email 已被占用。”] 中收到錯誤。 Below is SAP UI5 controller function where i am doing ajax call and I have also shared API as well.Can someone please identify where the problem is?

SAP UI5 Controller:

var url = "http://url/api/url";
    var data = {
    "picture" : "test",
    "member_cnic" : "weq",
    "sign" : "test",
    "ref_no" : "12345",
    "person_no" : "12345",
    "other_no" : "Othernumber",
    "first_name" : "Muhammad",
    "middle_name" : "adnan",
    "last_name" : "Aadi",
    "father_name" : "Muhammad",
    "dob" : "1992-02-10",
    "gender" : "Male",
    "cnic" : "0986543456",
    "passport_no" : "543456789",
    "nationality" : "pakistani",
    "religion" : "Lahore",
    "phone_no" : "09876543234",
    "email" : "test@gmail.com",
    "is_active" : "0",
    "academics[0][degree_examination]" : "xyz",
    "academics[0][pass_month]" : "6",
    "academics[0][pass_year]" : "2",
    "academics[0][session]" : "A",
    "academics[0][grade]" : "B+",
    "academics[0][division]" : "1st",
    "academics[0][organization]" : "UOL",
    "academics[0][is_exemption]" : "0",
    "academics[0][user_id]" : "2",
    "addresses[0][address1]" : "UOL",
    "addresses[0][address2]" : "UOL",
    "addresses[0][address3]" : "UOL",
    "addresses[0][address4]" : "UOL",
    "addresses[0][postal_code]" : "76554",
    "addresses[0][city]" : "Lahore",
    "addresses[0][district]" : "Lahore",
    "addresses[0][tehsil]" : "Bahria",
    "addresses[0][province]" : "Punjab",
    "addresses[0][country]" : "Pakistan",
    "addresses[0][region]" : "Bahria Town",
    "addresses[0][zone]" : "Lahore",
    "addresses[0][phone1]" : "083290273",
    "addresses[0][phone2]" : "343522242",
    "addresses[0][ext_no]" : "884",
    "addresses[0][fax]" : "345352626",
    "addresses[0][type]" : "Teacher",
    "addresses[0][mark_permanent_address_as_residential]" : "0",
    "addresses[0][user_id]" : "1",
    "experience[0][designation]" : "Manager",
    "experience[0][organization]" : "UOL",
    "experience[0][address]" : "Bahria",
    "experience[0][city]" : "Lahore",
    "experience[0][country]" : "Pakistan",
    "experience[0][start_date]" : "2010-02-10",
    "experience[0][end_date]" : "2010-02-10",
    "experience[0][is_current]" : "0",
    "experience[0][user_id]" : "12",
    "trainings[0][principal_mrt_name]" : "hello",
    "trainings[0][organization]" : "UOL",
    "trainings[0][city]" : "UK",
    "trainings[0][country]" : "UK",
    "trainings[0][crn]" : "2323",
    "trainings[0][start_date]" : "2010-02-10",
    "trainings[0][end_date]" : "2010-02-10",
    "trainings[0][address]" : "UOL",
    "trainings[0][user_id]" : "12",
    "mSettings[ref_no]" : "234",
    "mSettings[designation]" : "Manager",
    "mSettings[department]" : "cs",
    "mSettings[organization]" : "uol",
    "mSettings[publish_email1_in_directory]" : "0",
    "mSettings[publish_email1_in_mailing_list]" : "0",
    "mSettings[publish_email1_in_obituary]" : "0",
    "mSettings[publish_email2_in_directory]" : "0",
    "mSettings[publish_email2_in_mailing_list]" : "0",
    "mSettings[publish_email2_in_obituary]" : "0",
    "mSettings[publish_cell_in_directory]" : "0",
    "mSettings[publish_cell_in_mailing_list]" : "0",
    "mSettings[sms_facility]" : "0",
    "mSettings[period_of_residence_in_pakistan]" : "12",
    "mSettings[publish_communication_address_in_directory]" : "0",
    "mSettings[communication_address]" : "Town Lahore",
    }
    $.ajax({
         url: url,
         type: 'POST',
         mode: 'formdata',
         data: data,
         contentType: 'application/x-www-form-urlencoded',
         success: function(data){
             console.log("success"+data);
         },
         error: function(e){
             console.log("error: "+e);
         }
       });

API

{
"info": {
    "_postman_id": "9c7dbf23-21cb-4ec5-b7ee-b8794c8be930",
    "name": "Member Registration Copy",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
    {
        "name": "API",
        "item": [
            {
                "name": "http://url",
                "request": {
                    "method": "POST",
                    "header": [],
                    "body": {
                        "mode": "formdata",
                        "formdata": [
                            {
                                "key": "picture",
                                "type": "text",
                                "value": "wqe"
                            },
                            {
                                "key": "member_cnic",
                                "type": "text",
                                "value": "123"
                            },
                            {
                                "key": "sign",
                                "type": "text",
                                "value": "iopdpsad"
                            },
                            {
                                "key": "ref_no",
                                "value": "12345",
                                "type": "text"
                            },
                            {
                                "key": "person_no",
                                "value": "12345",
                                "type": "text"
                            },
                            {
                                "key": "other_no",
                                "value": "Othernumber",
                                "type": "text"
                            },
                            {
                                "key": "first_name",
                                "value": "Muhammad",
                                "type": "text"
                            },
                            {
                                "key": "middle_name",
                                "value": "adnan",
                                "type": "text"
                            },
                            {
                                "key": "last_name",
                                "value": "Aadi",
                                "type": "text"
                            },
                            {
                                "key": "father_name",
                                "value": "Muhammad",
                                "type": "text"
                            },
                            {
                                "key": "dob",
                                "value": "1992-02-10",
                                "type": "text"
                            },
                            {
                                "key": "gender",
                                "value": "Male",
                                "type": "text"
                            },
                            {
                                "key": "cnic",
                                "value": "0986543456",
                                "type": "text"
                            },
                            {
                                "key": "passport_no",
                                "value": "543456789",
                                "type": "text"
                            },
                            {
                                "key": "nationality",
                                "value": "pakistani",
                                "type": "text"
                            },
                            {
                                "key": "religion",
                                "value": "Lahore",
                                "type": "text"
                            },
                            {
                                "key": "phone_no",
                                "value": "09876543234",
                                "type": "text"
                            },
                            {
                                "key": "email",
                                "value": "test@gmail.com",
                                "type": "text"
                            },
                            {
                                "key": "is_active",
                                "value": "0",
                                "type": "text"
                            },
                            {
                                "key": "academics[0][degree_examination]",
                                "value": "xyz",
                                "type": "text"
                            },
                            {
                                "key": "academics[0][pass_month]",
                                "value": "6",
                                "type": "text"
                            },
                            {
                                "key": "academics[0][pass_year]",
                                "value": "2",
                                "type": "text"
                            },
                            {
                                "key": "academics[0][session]",
                                "value": "A",
                                "type": "text"
                            },
                            {
                                "key": "academics[0][grade]",
                                "value": "B+",
                                "type": "text"
                            },
                            {
                                "key": "academics[0][division]",
                                "value": "1st",
                                "type": "text"
                            },
                            {
                                "key": "academics[0][organization]",
                                "value": "UOL",
                                "type": "text"
                            },
                            {
                                "key": "academics[0][is_exemption]",
                                "value": "0",
                                "type": "text"
                            },
                            {
                                "key": "academics[0][user_id]",
                                "value": "2",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][address1]",
                                "value": "UOL",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][address2]",
                                "value": "UOL",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][address3]",
                                "value": "UOL",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][address4]",
                                "value": "UOL",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][postal_code]",
                                "value": "76554",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][city]",
                                "value": "Lahore",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][district]",
                                "value": "Lahore",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][tehsil]",
                                "value": "Bahria",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][province]",
                                "value": "Punjab",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][country]",
                                "value": "Pakistan",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][region]",
                                "value": "Town",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][zone]",
                                "value": "Lahore",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][phone1]",
                                "value": "083290273",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][phone2]",
                                "value": "343522242",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][ext_no]",
                                "value": "884",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][fax]",
                                "value": "345352626",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][type]",
                                "value": "Teacher",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][mark_permanent_address_as_residential]",
                                "value": "0",
                                "type": "text"
                            },
                            {
                                "key": "addresses[0][user_id]",
                                "value": "1",
                                "type": "text"
                            },
                            {
                                "key": "experience[0][designation]",
                                "value": "Manager",
                                "type": "text"
                            },
                            {
                                "key": "experience[0][organization]",
                                "value": "UOL",
                                "type": "text"
                            },
                            {
                                "key": "experience[0][address]",
                                "value": "Bahria",
                                "type": "text"
                            },
                            {
                                "key": "experience[0][city]",
                                "value": "Lahore",
                                "type": "text"
                            },
                            {
                                "key": "experience[0][country]",
                                "value": "Pakistan",
                                "type": "text"
                            },
                            {
                                "key": "experience[0][start_date]",
                                "value": "2010-02-10",
                                "type": "text"
                            },
                            {
                                "key": "experience[0][end_date]",
                                "value": "2010-02-10",
                                "type": "text"
                            },
                            {
                                "key": "experience[0][is_current]",
                                "value": "0",
                                "type": "text"
                            },
                            {
                                "key": "experience[0][user_id]",
                                "value": "12",
                                "type": "text"
                            },
                            {
                                "key": "trainings[0][principal_mrt_name]",
                                "value": "hello",
                                "type": "text"
                            },
                            {
                                "key": "trainings[0][organization]",
                                "value": "UOL",
                                "type": "text"
                            },
                            {
                                "key": "trainings[0][city]",
                                "value": "UK",
                                "type": "text"
                            },
                            {
                                "key": "trainings[0][country]",
                                "value": "UK",
                                "type": "text"
                            },
                            {
                                "key": "trainings[0][crn]",
                                "value": "2323",
                                "type": "text"
                            },
                            {
                                "key": "trainings[0][start_date]",
                                "value": "2010-02-10",
                                "type": "text"
                            },
                            {
                                "key": "trainings[0][end_date]",
                                "value": "2010-02-10",
                                "type": "text"
                            },
                            {
                                "key": "trainings[0][address]",
                                "value": "UOL",
                                "type": "text"
                            },
                            {
                                "key": "trainings[0][user_id]",
                                "value": "12",
                                "type": "text"
                            },
                            {
                                "key": "mSettings[ref_no]",
                                "value": "234",
                                "type": "text"
                            },
                            {
                                "key": "mSettings[designation]",
                                "value": "Manager",
                                "type": "text"
                            },
                            {
                                "key": "mSettings[department]",
                                "value": "cs",
                                "type": "text"
                            },
                            {
                                "key": "mSettings[organization]",
                                "value": "uol",
                                "type": "text"
                            },
                            {
                                "key": "mSettings[publish_email1_in_directory]",
                                "value": "0",
                                "type": "text"
                            },
                            {
                                "key": "mSettings[publish_email1_in_mailing_list]",
                                "value": "0",
                                "type": "text"
                            },
                            {
                                "key": "mSettings[publish_email1_in_obituary]",
                                "value": "0",
                                "type": "text"
                            },
                            {
                                "key": "mSettings[publish_email2_in_directory]",
                                "value": "0",
                                "type": "text"
                            },
                            {
                                "key": "mSettings[publish_email2_in_mailing_list]",
                                "value": "0",
                                "type": "text"
                            },
                            {
                                "key": "mSettings[publish_email2_in_obituary]",
                                "value": "0",
                                "type": "text"
                            },
                            {
                                "key": "mSettings[publish_cell_in_directory]",
                                "value": "0",
                                "type": "text"
                            },
                            {
                                "key": "mSettings[publish_cell_in_mailing_list]",
                                "value": "0",
                                "type": "text"
                            },
                            {
                                "key": "mSettings[sms_facility]",
                                "value": "0",
                                "type": "text"
                            },
                            {
                                "key": "mSettings[period_of_residence_in_pakistan]",
                                "value": "12",
                                "type": "text"
                            },
                            {
                                "key": "mSettings[publish_communication_address_in_directory]",
                                "value": "0",
                                "type": "text"
                            },
                            {
                                "key": "mSettings[communication_address]",
                                "value": "Town Lahore",
                                "type": "text"
                            }
                        ],
                        "options": {
                            "raw": {
                                "language": "json"
                            }
                        }
                    },
                    "url": {
                        "raw": "http://URL",
                        "protocol": "http",
                        "host": [
                            "127",
                            "0",
                            "0",
                            "1"
                        ],
                        "port": "8000",
                        "path": [
                            "api",
                            "MemberRegistration"
                        ]
                    },
                    "description": "Registration API "
                },
                "response": []
            }
        ]
    }
]

}

這是因為發送了相同的 email 地址。 代碼很好。 謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM