0

获取联系人

向http://ui-proj.practodev.in/contacts发出 GET 请求以获取联系人。

要按姓名、电子邮件或电话搜索联系人,请将搜索词作为查询参数“q”,例如http://ui-proj.practodev.in/contacts?q=test

API 将返回 HTTP 200 响应,其中包含所有联系人的 JSON,其中包含关键“联系人”

"contacts" : [{
   "id" : "1"
   "contact_name" : "Bob"
   "contact_phone" : "9876543210",
   "contact_email" : "bob@example.com"
}]

Here for fetching JSON data in client side my code so far;

$(document).ready(function(){

        $.ajax({
            type: 'GET',
            url:  'http://ui-proj.practodev.in/contacts',
            dataType: 'json',
   /*While accessing any of the urls from Contacts Demo API, 
   pass a header parameter X-USER with value as your email address to  authenticate.*/
   /*headers: {
    "X-USER" : 'bob@example.com"
   },*/
           beforeSend: function (request){
           request.setRequestHeader("Authority", authorizationToken);
           },
           success:function(data){
            $("#contacts").html(data);
           }
   });

});
4

1 回答 1

0

我在浏览器中打开了 www.google.com(任何 google 网站都可以,因为我在柬埔寨,我被重定向到 google.com.kh)

按 F12 并在控制台命令行中粘贴以下代码:

var s = document.createElement("script");
s.src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js";
document.body.appendChild(s);

单击运行(或在 Chrome 中按 Enter)

然后在命令行中粘贴以下代码(底部的控制台面板)

$.ajax({
    type: 'GET',
    url:  'http://ui-proj.practodev.in/contacts',
    data: {q:"test"},
    dataType: 'json',
    beforeSend: function (request){
      console.log("beforesend",request.setRequestHeader);
      request.setRequestHeader("X-USER", "the.user.you.sent@email.com");
   },
   success:function(data){
    console.log("success",data);
   }
   }).done(function() {
     console.log("youre not trying",this);
});

运行时找不到 404 用户,我认为当您发送已知用户凭据时它会起作用。

于 2013-11-03T08:12:28.693 回答