简体   繁体   English

JSON发布到API

[英]JSON Post to API

I am trying to make a JSON Post to the Simpleconsign API, and I keep receiving a 0 error from the browser. 我正在尝试将JSON发布到Simpleconsign API,并且始终从浏览器收到0错误。 Here is my code: 这是我的代码:

<script type="text/javascript">

JSONTest = function() {
    var resultDiv = $("#resultDivContainer");
    $.ajax({
        type: 'POST',
         key: "apikey,
        url: 'https://user.traxia.com/app/api/inventory', 
        contentType: "application/json",
         success: function(result){
            switch (result) {
                case true:
                    processResponse(result);
                    break;
                default:
                    resultDiv.html(result);
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
        alert(xhr.status);
        alert(thrownError);
        }
    });
};

</script>

I am a beginner at posting to the REST API's, so any help would be much appreciated. 我是发布到REST API的初学者,因此将非常感谢您的帮助。 Thank you! 谢谢!

I don't see any data in your Ajax POST? 在您的Ajax POST中看不到任何数据吗? This code should have work 该代码应该起作用

 var postData = { "key": "Your API Key Here", "query": "some query", "consignorId": "123456", "includeItemsWithQuantityZero": "false" }; JSONTest = function() { var resultDiv = $("#resultDivContainer"); $.ajax({ type: 'POST', data: postData, url: 'https://user.traxia.com/app/api/inventory', contentType: "application/json", success: function(result) { switch (result) { case true: processResponse(result); break; default: resultDiv.html(result); } }, error: function(xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(thrownError); } }); }; 

http://wiki.traxia.com/display/guide/List+and+Search+Inventory http://wiki.traxia.com/display/guide/List+and+Search+Inventory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM