3

I have a html page that can be accessed with the help of xampp locally on, http://localhost/testingserver/trelloapi.html.

That page looks like this, when opened in chrome this page loads fine and a card is created on my trello list. I swapped out the my_key etc so in my version I have in its place a long 12345abcsd...

trelloapi.html

<!DOCTYPE html>
 <html>
  <head>
    <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <script src="https://api.trello.com/1/client.js?key={my_key}&token={my_token}"></script>
  </head>
 <body>

<script type="text/javascript">

var myList = "{my_listId}";
var creationSuccess = function(data) {
  console.log('Card created successfully. Data returned:' +   JSON.stringify(data));
};
var newCard = {
  name: 'Making card from console 0.o', 
  desc: 'This is the description of our new card.',
  // Place this card at the top of our list 
  idList: myList,
  pos: 'top'
};
Trello.post('/cards/', newCard, creationSuccess);
</script>
</body>
</html>

But when I use PhantomJS with the following code, from http://phantomjs.org/ a card is not created on Trello

phantomcall.js

// Simple Javascript example
console.log('Loading a web page');
var page = require('webpage').create();
var url = 'http://localhost/testingserver/trelloAPI.html';
page.open(url, function (status) {
  console.log(status);
  //Page is loaded!
  phantom.exit();
});

I downloaded the phantomjs-2.1.1-macosx.zip containing a bin/phantomjs and use the command in terminal: $ sudo ./phantomjs ../../../Desktop/testingServer/phantomcall.js

and the following is printed in console:

Loading a web page

success

Jimmie
  • 397
  • 2
  • 5
  • 20
  • De website is successfully loaded but maybe there are errors on the page. Try to return the page document http://phantomjs.org/quick-start.html – J. Overmars Mar 25 '16 at 12:52
  • When I open the page in browser, in the console I get "Card created successfully. Data returned:{"id":"56f5....","badges":...." (long json response) with no errors. And I get a new card created in Trello. – Jimmie Mar 25 '16 at 12:54
  • 2
    Probably phantomjs not waiting for “full” page load - http://stackoverflow.com/questions/11340038/phantomjs-not-waiting-for-full-page-load – Yevgeniy Anfilofyev Mar 25 '16 at 13:00
  • Fantastic Yevgeniy, that did the trick. Post your answer and ill mark it – Jimmie Mar 25 '16 at 13:07

1 Answers1

3

I think it should be a good habit to be sure that page is fully loaded when working with javascript. So, probably the answer is here: phantomjs not waiting for "full" page load

Community
  • 1
  • 1
Yevgeniy Anfilofyev
  • 4,827
  • 25
  • 27