Sunday, July 21, 2019

Call Api with authentication in jquery or Call Api with authorization in jquery

1. Call Api with authentication in jquery or  Call Api with authorization in jquery
    or Call Api with authentication in ajax or  Call Api with authorization in ajax

function fn_item_list() {
        $.ajax({
            type: "GET",
            xhrFields: {
                withCredentials: true
            },
            headers: {
                'Authorization': 'Basic ' + 'admin:123'
                //'Authorization': 'Basic ' + btoa('admin:123')
            },
            url: "/api/Customers_",
            data: {
                cust_name: $("#cust_names").val()
            },
            success: function (data) {
                //alert(data);
                $("#div_item1 table tbody").empty();
                //var dt = JSON.parse(data);
                var dt = data;
                //alert(jsonObj.length);
                for (var i = 0; i < dt.length; i++) {
                    var sql = "<tr>";
                    sql += " <td>" + dt[i].cust_code + "</td>";
                    sql += " <td>" + dt[i].cust_name + "</td>";
                    sql += " <td onclick=fn_Edit('" + dt[i].cust_code + "') class='btn btn-success' ><i class='fa fa-trash' aria-hidden='true'></i></td>";
                    sql += " <td onclick=fn_Delete('" + dt[i].cust_code + "') class='btn btn-danger' ><i class='fa fa-trash' aria-hidden='true'></i></td>";
                    sql += "</tr>";
                    $("#div_item1 table tbody").append(sql);
                }
            },
            error: function (data) {
                alert("error : " + data);
            },
            failed: function (data) {
                alert("failed : " + data);
            }
        });
    };

No comments:

Post a Comment

Linq Expression syntax for where condtion in linq

(Expression<Func<T, bool>> filter)