0

I know, I know, "JS" in JSON and "j" in jQuery stands for JavaScript. Feel free to edit the title if you find a better formulation.

When I type in the URL "http://beep-beep" in my browser, I get a nicely formatted JSON file containing "{sound: 'beep', occurence: 2}", meaning the web service works as supposed to. Then I thought to myself: let's do that in CRM, in onLoad function for the creation of an entity. So, I'm trying to execute the following, copied directly from the SDK.

alert("Commence.");

$.ajax({
  type: "POST",
  url: "http://beep-beep",
  data: "{}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function (msg) {
    alert("Yippi!");
  }
});

alert("Finish.");

However, the code crashes telling me that "$" is not a defined symbol. Isn't jQuery an integral part of CRM JavaScript engine?! What am I missing here? Is there an easier way to consume a JSON feed?

bruce
  • 15
  • 3
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
  • @BenCameron Good guess! My jQuery isn't there... How does one refer it in a web resource in CRM 2011?! I've typed `alert($);` to see if I get `null`. And I got `null`. I was under impression that jQuery was an integral part of CRM 2011 by default... – Konrad Viltersten Nov 06 '12 at 16:22
  • I'm not sure about CRM but can you add an include in a masterpage or something similar? – Ben Cameron Nov 06 '12 at 16:24
  • 1
    Possible duplicate: [CRM 2011 “$ is undefined”](http://stackoverflow.com/questions/5168471/crm-2011-is-undefined) – Peter Majeed Nov 06 '12 at 16:26
  • @BenCameron Hehe, I'm only permitted to create a JS file and upload it to the server. No HTML, no MASTER, no nothin'. I've grade you up - good shot. But it didn't solved my problem (yet). :) I think Peter just gave me something to bite on. Apparently I was mistaken - no jQuery by default. I can try adding it as a web resource. All I really need is access to the JSON web service so it feels like a bit of overkill, but hey, as long as it works... – Konrad Viltersten Nov 06 '12 at 16:27
  • 1
    Ok, you've got a CRM 2011 issue now. I can't help you out with that. At least you know whats going wrong though. Good luck! – Ben Cameron Nov 06 '12 at 16:30
  • @KonradViltersten - would you please be able to mark my below answer as 'accepted'. I think we nailed this one a long time back! – Ben Cameron Dec 13 '16 at 16:43

3 Answers3

2

Have you included the jquery lib? Are you having the same issue as this... Object Expected error, javascript, jQuery

Community
  • 1
  • 1
Ben Cameron
  • 4,335
  • 6
  • 51
  • 77
  • Indeed we have. This is the longest someone ever has waited until asking me to accept an answer. You're an extremely patient person. Seriously though, what made you get back to this post? I'm very curious. :) – Konrad Viltersten Dec 13 '16 at 17:07
  • I was just looking back over my old posts and I noticed it. Thanks. – Ben Cameron Dec 13 '16 at 17:09
2

No, jQuery is not an integral part of CRM. There is an SDK example of using jQuery to consume the REST endpoint and it shows to include a jQuery web resource on the form.

http://msdn.microsoft.com/en-us/library/gg309549.aspx

Paul Way
  • 1,966
  • 1
  • 13
  • 10
0

Try changing

$.ajax({

to

jQuery.ajax({
keyboardSmasher
  • 2,661
  • 18
  • 20