Blogs

Set Up JQuery to Interact with the Smart Publish API

by User Not Found | Feb 06, 2012

What did we ever do before JQuery came about?  Back in the day, when we wanted to use AJAX to interact with services from the browser using javascript, we had to detect which browser was being used and use the appropriate objects to call the services. We then had to write browser specific code to update the UI since there were subtle differences in how to perform DOM manipulations in code.  Thanks to JQuery, all of those nuances have been abstracted and we can let the library take care of those subtleties. Here are some tips in getting JQuery to work for you when you want to call our Smart Publish API (SPA) services.  

At this point you should be signed up for our services and have set up an application through our Partner Workspace. Each application will have it's own APIKey which you will need to interact with our services.  The APIkey is passed in the header of each call to the SPA Services. Without this header, the service will return a "403 Forbidden" http code. 

JQuery makes it easy to set up default values for all ajax interactions by using the $.ajaxSetup function and we'll take advantage of that to make sure the APIKey is added to all calls.  In this example, we'll create a javascript function that  sets the request header value for Authorization and then in the $(document).ready function, we'll set the default ajax values. Don't forget to replace YOURAPIKEYHERE with the APIKey that you get from the Application Management Partner Workspace page (you'll need to be logged in to access that page). 

 

function AddAuthHeaders(xhr, settings) {

    xhr.setRequestHeader('Authorization', 'apikey=YOURAPIKEYHERE');
     //perform any other header updates you need here

}
 
$(document).ready(function () {
    //set default values for all of the service calls
    $.ajaxSetup({
        contentType: "application/json",
        dataType: "json",
        beforeSend: AddAuthHeaders
    });
}

 

Alright, we've gotten that authorization header out of the way, now we need to tell JQuery that it's ok to make cross origin scripting requests since the services are not hosted at the same URL as the web site.  Some browsers throw errors and some don't (Internet Explorer will complain with a "No Transport" error if you don't do this), so we can generally handle this by adding the following in the $(document).ready function:

 

jQuery.support.cors = true;

 

One last bit of housekeeping to take care of and that's to make sure the protocol of your AJAX requests are the same as the containing web page.  Usually what I do is keep a global javascript variable that contains the root of the RESTful requests including whether they should be called through http or https. I'll usually define the value in the $(document).ready by getting the window.location.protocol value and appending it to a constant for the service root URI. The SPA API requires all calls coming in to be through https, so at the point you're making the SPA calls, your page should be at an https URL.  Putting it all together, the $(document).ready function looks like this:

 

//defined up here so that they have global scope
var apiKey = "YOURAPIKEYHERE";
var serviceRootURI = "preview.webservices.fujifilmesys.com/spa/v2/"; //test URI
 
function AddAuthHeaders(xhr, settings) {
    xhr.setRequestHeader('Authorization', 'apikey=' + apiKey);
    //do any other header adds here
}
 
$(document).ready(function () {
    //set default values for all of the service calls
    $.ajaxSetup({
        contentType: "application/json",
        dataType: "json",
        beforeSend: AddAuthHeaders
    });
 
    jQuery.support.cors = true;
    serviceRootURI = window.location.protocol + "//" + serviceRootURI;
 
    //setup is complete, do other stuff now :)
});

With this code in the JQuery $(document).ready function and the AddAuthHeaders helper function, we're ready to start making calls to the Smart Publish API. The next blog entry will look at the use of our JQuery library for interacting with the individual services. Until then, feel free to leave us a comment to let me know what you think!

73 Comments

  1. 1 Andy 20 Sep
    Norton.com/setup
    download


    Downloading Norton setup online is not a difficult task if it
    is done in a proper procedure. Otherwise, it could be a tricky task. If you are
    willing to download the Norton comsetup in your computer system, then you need to first visit the website of
    Norton antivirus. 
  2. 2 HAPPY NEW YEAR 2018 MESSAGES 20 Sep
    <a href="https://www.happynewyear2018images.com/happy-dussehra-images-wishes-greetings-wallpapers-sms-for-whatsapp-facebook/">Dussehra wishes</a>,
    <a href="https://www.happynewyear2018images.com/happy-dussehra-images-wishes-greetings-wallpapers-sms-for-whatsapp-facebook/">Dussehra images</a>, 
    <a href="http://www.happynewyear2018.net/2017/07/happy-new-year-2018-facebook-dp.html">Happy dussehra wishes</a>,
    <a href="https://www.happynewyear2018images.com/happy-dussehra-images-wishes-greetings-wallpapers-sms-for-whatsapp-facebook/">Happy dussehra images</a>,
    <a href="http://www.happynewyear2018.net/2017/07/free-download-happy-dussehra-vijayadashami-images-wallpaers-cards-wishes-and-whatsapp-status-messages.html">Happy Dussehra 2017 wishes</a>,

    <a href="https://www.happynewyear2018images.com/happy-diwali-diwali-wishes-deepavali-whatsapp-status-diwali-video-diwali-greetings/">happy diwali quotes wishes</a>
    <a href="https://www.happynewyear2018images.com/happy-diwali-diwali-wishes-deepavali-whatsapp-status-diwali-video-diwali-greetings/">Happy diwali pics</a>
    <a href="https://www.happynewyear2018images.com/happy-diwali-diwali-wishes-deepavali-whatsapp-status-diwali-video-diwali-greetings/">happy diwali greetings</a>
    <a href="https://www.happynewyear2018images.com/happy-diwali-diwali-wishes-deepavali-whatsapp-status-diwali-video-diwali-greetings/">happy diwali 2017 images</a>
    <a href="https://www.happynewyear2018images.com/happy-diwali-diwali-wishes-deepavali-whatsapp-status-diwali-video-diwali-greetings/">happy diwali wishes</a>
    <a href="https://www.happynewyear2018images.com/happy-diwali-diwali-wishes-deepavali-whatsapp-status-diwali-video-diwali-greetings/">happy diwali images</a>
    <a href="http://www.happynewyear2018eve.com/2017/07/happy-diwali-images-wishes-sms.html">happy diwali greetings</a>
    <a href="http://www.happynewyear2018eve.com/2017/07/happy-diwali-images-wishes-sms.html">happy diwali 2017 images</a>
    <a href="http://www.happynewyear2018eve.com/2017/07/happy-diwali-images-wishes-sms.html">happy diwali wishes</a>
    <a href="http://www.happynewyear2018eve.com/2017/07/happy-diwali-images-wishes-sms.html">happy diwali images</a>
    <a href="http://www.happynewyear2018eve.com/2017/07/happy-diwali-images-wishes-sms.html">happy diwali 2k17 images</a>
    <a href="http://www.happynewyear2018eve.com/2017/07/happy-diwali-images-wishes-sms.html">happy diwali messages</a>

    <a href="http://www.happynewyear2018quotes.com/">Merry Christmas and a Happy New Year 2018</a>
    <a href="http://www.happynewyear2018quotes.net/">Merry Christmas and a Happy New Year 2018</a>
    <a href="http://www.happynewyear2018quotes.com/">Merry Christmas And Happy New Year 2018</a>
    <a href="http://www.happynewyear2018quotes.com/">New Year 2018 Wallpaper Free Download</a>

    <a href="http://www.happynewyear2018status.net/">Happy new Year 2018 Status</a>
    <a href="http://happynewyear2018greetings.com/">Happy New Year 2018 Greeting Cards</a>
    <a href="http://www.happynewyear2018quotes.com/">Happy New Year 2018 Quotes in Spanish</a>
    <a href="http://www.happynewyear2018quotes.com/">Happy New Year 2018 Wallpapers In Japanese</a>
    <a href="http://www.happynewyear2018quotes.com/">Happy New Year 2018 Images in Italian</a>
    <a href="http://www.happynewyear2018quotes.com/">Happy New Year 2018 Wishes In Hebrew</a>
    <a href="http://www.happynewyear2018wishes.com/">Merry Christmas New Year Quotes</a>
    <a href="https://www.happynewyear2018images.com/">Happy New Year 2018 Images Download</a>
  3. 3 https://greatpeople-me.co/ 19 Sep

    https://greatpeople-me.co/   worrying how to login into Greatpeople.me & Greatpeople.com Kroger is a well-known company
  4. 4 obat toxoplasma 16 Sep
    Makes me eager to read your blog, I also have an inspirational page
  5. 5 CheapWordpressHosting 14 Sep
    This is an awesome and really an informative guidance towards installation for Jquery to Interacet with smart pub API...Thanks

    Mens Biker Leather Jackets
  6. 6 HAPPY NEW YEAR 2018 MESSAGES 14 Sep
    <a href="https://www.happynewyear2018images.com/happy-dussehra-images-wishes-greetings-wallpapers-sms-for-whatsapp-facebook/">Dussehra wishes</a>,
    <a href="https://www.happynewyear2018images.com/happy-dussehra-images-wishes-greetings-wallpapers-sms-for-whatsapp-facebook/">Dussehra images</a>, 
    <a href="http://www.happynewyear2018.net/2017/07/happy-new-year-2018-facebook-dp.html">Happy dussehra wishes</a>,
    <a href="https://www.happynewyear2018images.com/happy-dussehra-images-wishes-greetings-wallpapers-sms-for-whatsapp-facebook/">Happy dussehra images</a>,
    <a href="http://www.happynewyear2018.net/2017/07/free-download-happy-dussehra-vijayadashami-images-wallpaers-cards-wishes-and-whatsapp-status-messages.html">Happy Dussehra 2017 wishes</a>,

    <a href="http://www.happynewyear0123456789.net/2017/08/happy-diwali-messages-diwali-messages.html">Happy diwali 2017 wishes</a>,
    <a href="http://www.happynewyear0123456789.net/2017/08/happy-diwali-messages-diwali-messages.html">Happy diwali wishes</a>,
    <a href="http://www.happynewyear0123456789.net/2017/08/happy-diwali-messages-diwali-messages.html">Happy diwali 2017 images</a>, 
    <a href="http://www.happynewyear0123456789.net/2017/08/happy-diwali-messages-diwali-messages.html">Happy diwali images</a>,
    <a href="http://www.happynewyear2018.net/2017/07/happy-new-year-2018-facebook-dp.html">Happy diwali 2017 quotes</a>, 
    <a href="http://www.happynewyear2018.net/2017/07/happy-new-year-2018-facebook-dp.html">Happy diwali quotes</a> 

  7. 7 Mumbai to Goa Cab hire 12 Sep
    Thanks on your marvellous posting! I certainly enjoyed reading it. I will remember to bookmark your blog and will eventually come back from now on. I want to encourage that you continue your great writing, have a nice day!
  8. 8 jewellerkaka 07 Sep
    great..
    <a
    href="https://www.jewellerkaka.com/shop-2/necklace-sets-women-designer-fashion-necklaces-india/beautiful-drop-shape-red-crystal-necklace-set/">beautiful-drop-shape-red-crystal-necklace-set</a>
  9. 9 Love quotes for Him 07 Sep
    Very Interesting Article
     <a
    href="https://www.lovequotesforu.com/love-quotes-for-him/">New
    Motivational and Romantic Love quotes 
    my dear</a>

    <a
    href="https://www.lovequotesforu.com/love-quotes-for-him/">New
    Interesting Love quotes  Him</a>
  10. 10 Michael Doherty 06 Sep
    Many thanks for sharing this very diverse opinion post where each expert has no doubt shared his best knowledge on the topic. Have more success in your journey. 
    Finance Assignment Help
  11. 11 Happy Anniversary Quotes 06 Sep
    Very great info.

    <a
    href="https://www.lovequotesforu.com/happy-anniversary-wishesmarriagewedding-anniversary-wishesquotes//">Best
    Anniversary wishes for hubby</a>
  12. 12 Team 365 Jacket TT80Y 24 Aug
    Here's everything we know about the OnePlus 4. Get Release Date
  13. 13 JILL 23 Aug
  14. 14 kyla 18 Aug
    Your writing is easy to understand and has benefits for all of us <a href="http://www.tokoqnc.com/">pemulihan ligamen robek</a>
  15. 15 Wifi password hacker software free download for mobile 11 Aug
    nice post
  16. 16 facetime for windows 05 Aug
    FaceTime is one of them. There are evergreen choices from which individuals can pick.
    facetime for windows
  17. 17 https://lawassignmentshelp.com/ 04 Aug
    https://lawassignmentshelp.com/This is really great work. Thank you for sharing such a good and useful information here in the blog for students.

  18. 18 https://www.psychologyassignments.com/ 04 Aug
    I am so happy to read this. This is the kind of manual that needs to be given and not the random misinformation that's at the other blogs.

    https://www.psychologyassignments.com/
  19. 19 chelsieanayas 04 Aug
    Just a smile and the rain is gone Can hardly believe it, yeah. There's an angel standing next to me. Reaching for my heart Just a smile and there's no way back .Can hardly believe it, yeah But there's an angel calling me. Reaching for my heart I know that I'll be okay now. This time, it's real I lay my love on you It's all I wanna do Every time I breathe I feel brand new You open up my heart Show me all your love and walk right through As I lay my love on you. } dumb ways to die } fireboy and watergirl 4
  20. 20 21 questions game 29 Jul

    The next time I read a blog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my choice to read, but I actually thought you have something interesting to say. All I hear is a bunch of whining about something that you could fix if you werent too busy looking for attention.  21 questions game

  21. 21 copyright free images 28 Jul
    well it's a nice info for the developers many thanks you can try free image hosting site to get copyright free images
  22. 22 Questions to ask 27 Jul
    I will really appreciate the writer's choice for choosing this excellent article appropriate to my matter.Here is deep description about the article matter which helped me more.  Questions to ask

  23. 23 Ryker 25 Jul
    I was reading the provide article with great interest.This post is very usefull and informatative.
    Fraps Full Version Free
    Power ISO Full
    Zenmate premium Crack
    Doom Cracked
    CleanMyPC Crack
    Portforward Network Utlities
    DVDFab Crack
  24. 24 David Cyryl 25 Jul
    An amazing article you compose, exceptionally intriguing and educational. I trust you will continue composing articles in the same class as this, so I increased broad knowledge. You're the best! PhD Dissertation Writing Services
  25. 25 Kristan 17 Jul
  26. 26 Eset nod32 antivirus 10 crack 2017 11 Jul
    <a href="http://crack55.com/eset-nod32-antivirus-9-username-or-password/">Eset nod32 antivirus 9 activation key 2018</a>
  27. 27 idm crack 10 Jul
  28. 28 a10 08 Jul
    It is my first time I visit here. The way you create a website very thorough and good. This is very very impressive. I found so many entertaining stuff in your blog, especially its discussion. I will continually be coming on a regular basis you just read your posts.
    a10, color switch, animal jam
  29. 29 Help With Biology Assignment 01 Jul
    by visiting this site I found cool stuff here keep it up.Help With Biology Assignment
  30. 30 BBA Assignment Help 01 Jul
        Pretty helpful material, much thanks for this article
    BBA Assignment Help
  31. 31 Tom Hardy Bane Vest 22 Jun
    Interesting article! Thank you for sharing them! I hope you will continue to have similar posts to share with everyone.
  32. 32 windows 7 loader activator 22 Jun
    good post
  33. 33 windows 7 loader by daz 22 Jun
    nice post
  34. 34 windows 7 loader activator 22 Jun
    good
  35. 35 mobdro for ios 22 Jun
    Mobdro is a smart movie organiser and based on the internet, the app will automatically determine the quality of the movie
  36. 36 Brand designs 21 Jun
    This is an awesome post..thanks a lot

    brand designs
    website designs
  37. 37 Download Key 15 Jun
    [url=http://crack55.com/]Download full version[/url]
    This is Very Nice Post Fantastic material and amazing article.I most want to say that you are doing a great job.Thanks for this nice article.[url=http://crack55.com/]Download full version[/url]
  38. 38 Sophie 15 Jun
    This is an exceptional post I seen on account of offer it. It is really what I anticipated that would see search for in future you will proceed with consequent to sharing such a dazzling smart. Top Gun Brown Jacket

  39. 39 assignment providers help 12 Jun
    ADHD is a tough situation to be in for families and patients. Of course, parents are hoping their children will grow up to be healthy, but things happen along the way. That’s why science is there to explain and seek solutions. I hope more young kids aspire to be scientists or be involved with the field of science. They can end up as scientists, botanists, biologists, doctors of medicine, and other noble professions. I hope they make the right choice.
    assignment providers help
  40. 40 Case Study Help 08 Jun
    An incredible article you write, very very interesting and informative. I hope you will keep writing articles as good as this, so I gained extensive insight. Thanks a lot! 

    Case Study Help
  41. 41 YUYU 07 Jun
    Much interesting article and I am so delighted to be here and to gather this awesome post. Thanks a lot sir. fake yeezy boost 350 for sale
  42. 42 opopo 07 Jun
    Much interesting article and I am so delighted to be here and to gather this awesome post. Thanks a lot sir. <a href="http://www.yeezy350find.com/">fake yeezy boost 350 for sale</a>
  43. 43 Cheap Lebron James Sneakers 06 Jun
    <a href="http://www.cerquit.com/">Cheap Lebron James Sneakers</a> with hyperposite midsole, these shoes provides strong support for fast movement.
  44. 44 Buy Cheap Essay 30 May
    Notice something different around here? That’s right -- we’ve given our website a bit of a facelift! We’re pleased to unveil our new look, with a sleeker design and easier-to-find features. Our new site more effectively highlights what’s most important to us and to our community. Plus, it’s mobile-friendly (hello, 21st century!), so you can browse FAoS opportunities and resources on the go.
  45. 45 swiggy android app 27 May
    swiggy android app
    This article was written by a real thinking writer.
  46. 46 cheap authentic jordans 26 May
    Mens Air Jordan 12 has genuine leather upper for durable comfort.Mens The Air-Sole units offers excellent cushioning for Air Jordan 12.
  47. 47 David Clark 26 May
    Thanks for this wonderful info
    Checkout this awesome article : How to Jailbreak Roku
  48. 48 david clark 26 May
    Thanks for the information .
    Do check out this link : How to Jailbreak Roku
  49. 49 aptoide for pc 18 May
    best alternative for the Google Play store available on the market is the Aptoide for pc
    <a href="https://iaptoideapk.org/aptoide-for-pc-on-windows/">aptoide for pc</a>
  50. 50 official tricksmaze.com 01 May
    <a href="https://tricksmaze.com/">www.tricksmaze.com</a>

  51. 51 stevesmith 27 Apr
    I guide the students that how they can pass the exams and how can they get the certification for the latest knowledge this certification exam students click at c_hanaimp_11 syllabus its certification its better for your bright future and will helpful to attain the IT certification
  52. 52 John Mathew 24 Apr
    Such a great click
  53. 53 ppsspp gold apk 16 Apr
    ppsspp gold apk available here  
  54. 54 marathi dj songs 16 Apr
  55. 55 tutu app pokemon go 06 Apr
    Tutu app Pokemon go is a Chinese origin application which is a free application for android and ios users. This application was developed by Chinese developers to make the games better as compared to their available versions. 
    <a href="http://tutuapps.org/tutuapp-pokemon-go-hack-download/"/>tutu app Pokemon go</a>

  56. 56 Tutu app Pokemon go 06 Apr
    Tutu app Pokemon go is a Chinese origin application which is a free application for android and ios users. This application was developed by Chinese developers to make the games better as compared to their available versions. 
    <a href="http://tutuapps.org/tutuapp-pokemon-go-hack-download/"/>tutu app pokemon go</a>
  57. 57 mpresults.nic.in 05 Apr
    www.mpresults.nic.in : we are going to provide you the information regarding MP Board 10th Result 2017 
    mpresults.nic.in

  58. 58 Robert 29 Mar
    Developers are allowing us to get at their data much more Money Converter transparently now, never again is everything safety secured. Sites are pleased to have you get their information and actually.
  59. 59 Jack kevin 22 Mar
    Engineers are permitting us to get at information substantially more Custom Assignment Help straightforwardly now, never again is everything safety guarded. Sites are pleased to have get to their information and, truth be told, energize it.
  60. 60 Joseph Dahlgren 20 Mar
    Hi! I really sympathize with your situation. I'm going through the same thing right now and have looked into the manga industry and found opportunities for manga artists to publish their own original titles are quite limited. Yen Press is the only prominent publisher working on OEL titles right now and they are largely concentrating on adapting properties with already built in audiences. James Patterson and other YA books like the Parasol Protectorate series. My suggestion is to definitely launch it as a webcomic, build a following cheap custom essay online and self-publish the work yourself. Yes, indeed, it is a lot of hard work but trust me when I say this hard work pays off. You will come to understand the publishing process intimately, will have more control over the way your book is presented and do marketing on your own terms using Facebook, Twitter. Understanding what goes into a successful launch of a book better equips you to approach a publisher down the road. As a beginner, you don't have enough clout to negotiate terms with them unless 1 You are up to your ears in talent or 2 you already have a strong following through other means via Deviantart etc.
  61. 61 swiggy hyderabad offers 23 Feb
    Thanks for the post
  62. 62 best gaming mouse under 50 04 Feb
    <a href="https://bestgamingmouse2017.org/">best gaming mouse</a>


  63. 63 Bishop consultancy 03 Feb
    I have known about JQuery yet don't comprehend what it does. Like what does it really JQuery convey to a site? For instance, i need a live webcam talk on my assignment help UK site. In the event that i utilize JQuery by what means will it help me?
  64. 64 jimmy 22 Jan
    http://apkspeed.com visit now if you want to download best apk apps
  65. 65 James Cameron 19 Jan
    The agenda utilize JavaScript, we wanted to know which plan was being Buy Assignment utilize the appropriate substance to call the administration. We then required composing agenda exacting system to overhaul.
  66. 66 download Kik messenger for laptop 10 Jan
    Kik for PC on Windows 10/8.1/8/7. download Kik messenger for laptop & MAC using Bluestacks & Android.
  67. 67 How To Write A Research Paper 06 Jan
    JSON-based APIs are a hot property on the Web at this moment. I can't recall the last time I went onto a blog or portfolio without seeing the proprietor's tweets or Facebook companions How To Write A Research Paper gazing back at me. This intuitiveness makes the Web an energizing spot. As far as possible is by all accounts individuals' creative energy. As exhibited by everything from pulled tweets to a mindful trade rates API, information is at present ruler, and sites are swapping it uninhibitedly.
  68. 68 llya 15 Dec

    <a href="http://www.itFFFF.com/">bgfgfhsg</a>[url=http://www.itFFFF.com/]wendyouyt[/url]
  69. 69 SBI UPI App 09 Dec
    Learn How to download SBI UPI App. You can easily transfer money without using the bank account details of the payee through the SBI Pay App.
  70. 70 New Year 2017 Images 08 Dec
    That’s why people are looking for the New Year Wishes, quotes and messagesThat’s why people are looking for the New Year Wishes, quotes and messages


  71. 71 OnePlus 5 Specs 06 Dec
    Here's everything we know about the OnePlus 4. Get Release Date, Price, Features, Rumors and Specifications of OnePlus 4.
    OnePlus 5 Specs

  72. 72 agjsgf 16 Nov
    Coaching makes the pre-adult careful. In custom dissertation writing services countries sex preparing has amazing congruity. Sex preparing is extremely helpful to supervise secondary school pregnancy. Sex guideline moreover offers information to sexually sent ailments.
  73. 73 dumpy 24 May
    great

Comment

  1.