0

I have a situation where, when I send an ajax call through visualforce page by adding jquery through

<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>

and making ajax call like this :

    jQuery.getJSON('https://localhost:44321/Api/SFGetData?callback=?&mType=ad&isRequired=false', function(json){
      console.debug(json.Data);
    });

Now when I made a lightning component and added jquery from static resource like this :

<ltng:require scripts="{!$Resource.jquery}"
afterScriptsLoaded="{!c.doInit}" />

and then calling ajax request in doInit function like this again :

        jQuery.getJSON('https://localhost:44321/Api/SFGetData?callback=?&mType=ad&isRequired=false', function(json){
           console.debug(json.Data);
        });

The difference that I am able to find here is that the 1st call which gives correct data has initiator = "jquery-3.3.1.min.js:2" and initiator of 2nd call is : aura_prod.js:15

The initiators were verified from Chrome developer console in Network tab :

Image is posted here : Chrome Developer Console Screenshot

7
  • rattanpal.com/2017/09/03/…
    – gNerb
    Commented Aug 27, 2018 at 15:35
  • @gNerb Can this be because I am using jquery 2.2.4? Commented Aug 27, 2018 at 15:39
  • It's because you're using jquery at all. Lightning is it's own complicated feature rich framework. Many of the things you want to use jquery for don't work in lightning components such as manipulating the dom. Rather than trying to import a library that you are comfortable with, you need to learn how to use the libraries provided by SFDC.
    – gNerb
    Commented Aug 27, 2018 at 15:40
  • Ok, but in my calls i have to send callback parameter to server and jquery handles it for me, how can i send callback from xmlhttprequest? Commented Aug 27, 2018 at 15:43
  • jquery is just a library built on top of JS if jquery can do it you can do it too. Just google for some help. You can also ask questions like that on stackoverflow.com
    – gNerb
    Commented Aug 27, 2018 at 15:45

0

You must log in to answer this question.