[SalesForce] jquery in Lightning component

Does anyone have any examples of how to make a jQuery get from a Lightning component using code similar to the below where the data will be returned from SOQL query in Salesforce

jQuery.ajax({
url: '/MCS/GetCar',
type: "GET",
dataType: "json",

I am already aware of how to import the jquery library using ltng:require and creating an @AuraEnabled method in Apex but it was wiring the rest together I was unsure about, I am relatively new to Lightning although aware of the basics.

Thanks

Best Answer

For client/server communication you'll want to go through the standard Aura APIs instead of jQuery.ajax(). I recommend going through the full Develop for Lightning Experience Trailhead module if you're new to Lightning component development. Or if you've already gone through that, I'd revisit the Connect to Salesforce with Server-Side Controllers section.

You were on the right track with the @AuraEnabled method. Instead of calling ajax() though you'll want to create an Aura action by getting it from your component instance var action = component.get("c.getExpenses");, and then firing it via enqueueAction $A.enqueueAction(action);. See the Trailhead module for the full example and how to handle the response.