尝试使用CURL,JSON和Web服务调用通过ajax发布表单

时间:2013-10-22 18:43:14

标签: jquery ajax json web-services curl

您好我一直在尝试将字段发布到客户端提供的Web服务中。 客户给我的具体文件等使用有例。

我是webservices的新手,但我打赌我很接近......这里的结果就是客户端 希望我发送。

以下是使用cURL的一些示例/文档:

$ curl --data '{"firstname": "William S.", "lastname": "Walker", "language": "EN", "city": "Ottawa", "state": "ON", "country": "CA", "telephone": "613-737-5719", "mobilephone": "613-737-5719", "fax": "613-737-5719", "email": "WilliamSWalker@rhyta.com", "entreprise": "Helping Hand", "passtype": "None", "passwordchanged": false, "professionalactivity": "Respiratory care practitioner", "registrationdate": "2010-04-20T20:08:21", "sectorofinterest": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam quis nisl vestibulum, egestas enim vel, egestas erat. Aenean sodales ipsum tortor, ut facilisis elit fermentum eget.", "webpage": "http://www.GolfCleaners.com", "workplace": "Helping Hand"}' -X POST -H 'Authorization: Token token="token"' https://link.mobile.test.com/api/v1/conferences/4/participants

即时尝试使用ajax发送并发布到此功能。 这是我的ajax

function addAttendee(){

$.ajax({
    url: "https://link.mobile.test.com/api/v1/conferences/4/participants",
    type: "POST",

    dataType: "html",
    data: "firstname=Kevin&lastname=Gauthier&telephone=4502605353&email=kevin@konige.com&token=7f5cebd3b6c62559f53d1179571e10da",
    contentType: "application/json; charset=utf-8",
    success: function(data) {
        // handle your successful response here
    },
    error: function(xhr, ajaxOptions, thrownError) {
        // handle your fail response here
    }
});
}

我不明白的是,这将返回 HTTP令牌:拒绝访问。
有人可以帮助我现在很困惑。

也许只是我,我不理解网络服务的概念。

提前致谢

1 个答案:

答案 0 :(得分:1)

这是一个示例AJAX调用,我今天刚用它来在Jquery中发布数据。

 $.ajax({
        type: "POST",
        url: "/feedbacks.json",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: JSON.stringify({ category: "categoryType", message_text: "messageString", anonymous: "anonymous_user" ,other_information: "otherInfo", browser_name: "browser_info", ssm_version: "ssmVersion"}),
        success: function () {
            window.close();
        },
        error: function(model, response) {
            var errMsg = "Your feedback could not be submitted."
            window.appEvents.trigger(UIEvents.app.failure, errMsg, 'modal')
        }
    });