• Scott Krause
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Hi,

 

I need to implement a REST service that returns data in JSONP format (JSONP format required for cross-domain ajax calls). I'm calling this service by jQuery ajax. But it always raises error : Error jQuery17109439062654184185_1342893046903 was not called.

The reason is that REST API only supports JSON and XML. In this case JSONP always returned as a XML. I'm wondering is there any workaround for this?

 

Here is my apex code:

 

@RestResource(urlMapping='/BookingService/*')
global class noqBookingService {

global class BookingStatus {
    global String ReferenceId { get; set; }
    global integer Threshold { get; set; }
}

@HttpGet
    global static String getQueueStatus() {
        String referenceId = req.params.get('referenceId');
        String jsonp_callback = req.params.get('callback');
        
        BookingStatus status = new BookingStatus();
        status.ReferenceId = referenceId;
        status.Threshold = 8;
        System.debug(jsonp_callback+'(['+JSON.serialize(status)+'])');
        
        return jsonp_callback+'(['+JSON.serialize(status)+'])';        
    }    
}

 Visualforce code:

 

$(document).ready(function() {
        $.ajax({
            url:'https://My-Site-Domain/services/apexrest/BookingService?callback=?',
            type:'GET',
            dataType: 'jsonp',
            contentType: 'application/javascript',
            success: function(status){ alert('success');},
            error:function(xhr, ajaxOptions, thrownError){ alert('error:'+thrownError);}
        });
    });

 

  • July 21, 2012
  • Like
  • 0