weixin_33675507 2013-08-05 21:02 采纳率: 0%
浏览 33

REST调用Javascript

How do I make a call to a REST Api with Javascript (or ajax or jquery)?

curl -v -X PUT -H "Content-Type: application/json" -H "Accept: application/json" -X PUT --user user:password http://url -d "{\"name\": \"Marcus0.2\",\"start\": 1361381326000,\"end\": 1361640526000}"

I need help converting this to a useable ajax call. Thanks

$.ajax({
    type: 'put',
    url: 'https://this.is.my/url',
    dataType: 'json',
    data: { \"name\": \"Marcus0.3\" , \"start\": 500000 , \"end\": 1361640526000 }
    });

This code does not work [not sure why]. Also, 'https://this.is.my/url' is just short for the longer url, which I don't want to post online

  • 写回答

1条回答 默认 最新

  • weixin_33728708 2013-08-05 21:12
    关注

    No need to add escaping to your data element... you can send a whole object and jQuery will take care of it for you.

    $.ajax({
      type: 'put',
      url: 'https://this.is.my/url',
      dataType: 'json',
      data: {
        name: 'Marcus0.3', 
        start: 500000,
        end: 1361640526000 
      }
    });
    
    评论

报告相同问题?