Fetch Link from my server and put content when clicked on link

71 views
Skip to first unread message

Bhavesh Vaghela

unread,
May 12, 2017, 9:22:03 AM5/12/17
to InboxSDK
InboxSDK.load('1.0', 'myseverapp').then(function(sdk){
  sdk.Compose.registerComposeViewHandler(function(composeView){
    composeView.addButton({
      title: "My Nifty Button!",
      onClick: function(event) {
        event.composeView.insertBodyTextAtCursor('Hello World!');
      },
      hasDropdown: true,
      onClick: function(event) {
          console.log(event);
          event.dropdown.el.innerHTML = 'hello world!';
           
        },
     
      orderHint: 0
    });
  });
});

I want a dropdown with title and link from server when user click on title it will fetch content from that title
How to do?
I have just started with Inboxsdk from Yesteday, I spent 16 hours to understand without any luck.
Please help!

Chris Cowan

unread,
May 12, 2017, 2:06:26 PM5/12/17
to InboxSDK
Here's an example that makes an ajax request to include some html from a remote page:

InboxSDK.load('1.0', 'myseverapp').then(sdk => {
  sdk.Compose.registerComposeViewHandler(composeView => {
    composeView.addButton({
      title: "My Nifty Button!",
      hasDropdown: true,
      onClick(event) {
        event.dropdown.el.innerHTML = 'Loading...';

        fetch('https://example.com/foo.html')
          .then(response => response.text())
          .then(text => {
            event.dropdown.el.innerHTML = text;
          })
          .catch(err => {
            console.error(err);
            event.dropdown.el.textContent = 'There was an error loading this content.';
          });
      },
      orderHint: 0
    });
  });
});


In this example I'm using the newer `fetch` API which is well-supported in Chrome now. Note that by default, fetch does not include cookies in its requests. If you need cookies, then use

fetch('https://example.com/foo.html', {credentials: 'include'})


Bhavesh Vaghela

unread,
May 12, 2017, 2:16:16 PM5/12/17
to InboxSDK
Suppose https://example.com/foo.html gives output in html with list of title. when user click on title it will fetch full html from server
Basically what I want is to fetch all temple title from my server when user click on title it will fetch its content and put into gmail compose body.
Reply all
Reply to author
Forward
0 new messages