Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Salesforce by (11.9k points)

I am trying to get data from salesforce API using SOQL method. Problem is that when sending ajax getting request it encodes URL that results in failure of $ajax request.

How can I send plain URL in ajax request without encoding URL?

A sample request is HERE:

    $.ajax({

                             type: "GET",

                             url: "https://ap1.salesforce.com/services/data/v35.0/query?q=SELECT Id FROM Contact WHERE Email= '" + Email + "'",

                             headers: {

                                 "Authorization": "OAuth " + access_token,

                                 'Content-Type': 'text/plain'

                             },

                             crossDomain: true,

                             dataType: 'application/json',

                             success: function (responseData) {

                                 console.log(responseData);

                             },

                             error: function (request, status, error) {

                                 console.log(request.responseText);

                             }

                         });

1 Answer

0 votes
by (32.1k points)
edited by

It seems like it returns an undefined response and plain text URL without special chars so that SOQL can be executed. Right? So, for that, try using the following things:

  1. q=SELECT Id FROM Contact WHERE Email= '" + Email should work fine in postman it returns response data.
  2. replace the spaces with "+" 
Become a certified Salesforce professional by going for Intellipaat’s Salesforce Certification!
 

Browse Categories

...