Force.com:查询中的Rest API错误请求

时间:2013-08-15 03:38:45

标签: apex-code force.com

我在下面的Rest API Ajax调用中收到'错误请求'消息,当我在Developer Console上测试时,它成功返回数据。

var _url = auth.get("instance_url") +
    "/services/data/v28.0/query/?q=SELECT Id, Name FROM  Account WHERE Website LIKE '%gmail.com%' ";

$.ajax({
    url: _url,
    cache: false,
    async: false,
    type: 'GET',
    contentType: 'application/json',
    headers: {
        'Authorization': 'OAuth ' + auth.getAccessToken()
    },
    success: function (data) {
        console.log("accounts:  " + JSON.stringify(data));
        result = data;

    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
        alert(textStatus + +errorThrown);
    }
});

1 个答案:

答案 0 :(得分:0)

您需要URLEncode查询参数,空格在查询字符串中无效,例如

var _url = auth.get("instance_url") + "/services/data/v28.0/query?q=" + encodeURIComponent("select id,name from account");