Advertisement
Guest User

Cross-domain AJAX

a guest
May 31st, 2011
3,009
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.25 KB | None | 0 0
  1. <html><head>
  2.     <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.css" />
  3.     <script src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
  4.     <script src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>
  5.  
  6.     <script type="text/javascript">
  7.         $( function() {
  8.             $('#loadBtn').bind ( 'click', function(){ load(); } );
  9.         } );
  10.        
  11.         var linkUrl = "http://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&lang=en";
  12.        
  13.         var load = function() {
  14.             $.ajax(
  15.             {
  16.                 dataType : "jsonp",
  17.                 jsonp : "jsonp",
  18.                 url : linkUrl,
  19.                 error : function(data) {
  20.                     alert("Error - 2");
  21.                 },
  22.                 success : function(response){
  23.                     document.getElementById("quote").innerHTML = response.quoteText;
  24.                     document.getElementById("author").innerHTML = response.quoteAuthor;
  25.                 }
  26.             });
  27.         };
  28.     </script>
  29. </head>
  30.  
  31. <body>
  32.     <div data-role="page" id="main">
  33.         <div data-role="header">
  34.             <h1>Forismatic Sample App</h1>
  35.         </div>
  36.         <div data-role="content">
  37.             <a id="loadBtn" data-role="button">Load</a><br>
  38.             <div id="quote" style="font-weight: bold;"></div><br>
  39.             <div id="author"></div>
  40.         </div>
  41.         <div data-role="footer" data-position="fixed">
  42.         </div>
  43.     </div>
  44. </body></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement