查询字符串

时间:2016-11-03 07:44:42

标签: javascript jquery ajax rest

我在REST api的ajax请求中遇到以下错误

  

" NetworkError:400错误请求 - http://192.168.2.45:8080/engine-rest/external-task/fetchAndLock/?callback=jQuery111008749113014618789_1478158463319& {%22workerId%22:%22worker01%22,%22maxTasks%22:5,%22topics%22:[{%22topicName%22:%22correctionOfData %22,%22lockDuration%22:10000,%22variables%22:[%22Applicant_Name%22]}]}&安培; _ = 1478158463320"   ?callba ... 8463320

Ajax代码

<script type="text/javascript">
    require(['jquery'],function($) {
        var REST_BASE_URL = "http://192.168.2.45:8080/engine-rest";
        function receiveExternalTasks(topicName) {
            var fetchRequest = {
                "workerId":"worker01",
                "maxTasks":5,
                "topics": [
                    {
                        "topicName": topicName,
                        "lockDuration": 10000,
                        "variables": ["Applicant_Name"]
                    }
                ]
            }

            $.ajax(REST_BASE_URL + '/external-task/fetchAndLock/', {
                data: JSON.stringify(fetchRequest),
                dataType : "jsonp",
                contentType: "application/json; charset=utf-8",
                type : 'POST',
                beforeSend: function(xhr){xhr.setRequestHeader('Access-Control-Allow-Origin', '*');},
                success: function (result) {

                    for (var index = 0; index < result.length; ++index) {
                        var externalTask = result[index];
                        console.log(externalTask);
                        addRowToTable('table' + topicName, JSON.stringify(externalTask));
                        $.ajax(REST_BASE_URL + '/external-task/' + externalTask.id + '/complete', {
                            data: JSON.stringify({"workerId":"worker01"}),
                            dataType : "jsonp",
                            contentType: "application/json; charset=utf-8",
                            type : 'POST'
                        });
                    }
                }
            });
        };

        $(document).ready(function(){

            $("button").click(function(){
                receiveExternalTasks('correctionOfData');
            })


        });

    });
</script>           

请注意上面的错误,%22 在查询字符串中添加,我怀疑可能会导致此错误。我不知道如何删除%22

您可以找到完整的源代码here

0 个答案:

没有答案