Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]Pobieranie danych w js z zewnętrzego serwera
fiasko
post
Post #1





Grupa: Zarejestrowani
Postów: 243
Pomógł: 1
Dołączył: 1.06.2010

Ostrzeżenie: (0%)
-----


[JAVASCRIPT] pobierz, plaintext
  1. $(document).ready(function(){
  2.  
  3. $.ajax({
  4. type: 'POST',
  5. url: 'http://www.xxxx.pl/gadzet/content.php',
  6. data: ({
  7. action : 'new_product',
  8. }),
  9. dataType: "html",
  10. success: function(data){
  11.  
  12. alert("odpowiedz"+data);
  13.  
  14. //$('#content').append(msg);
  15.  
  16. },error: function(xhr,err){
  17. alert('Brak odpowiedzi serwera');
  18. alert('readyState: '+xhr.readyState+' ');
  19. alert('responseText: '+xhr.responseText);
  20. }
  21.  
  22. });
  23.  
  24.  
  25.  
  26.  
  27. });
[JAVASCRIPT] pobierz, plaintext



Jak to uruchamiam na serwerze z którego szczytuje dane to śmiga . Czyli alert poprawnie się wyświetla wraz z danymi.

Jak uruchamiam to lokalnie na komputerze to funkcja success się wykonuje - ale wyświetla mi alert z pustymi danymi . Czyli mam

Odpowiedz i pusto - brak danych .


A musi mi skrypt zasysać dane z zewnętrznego serwera . Gdziekolwiek to uruchomię.

How to ?

Ten post edytował Ociu 18.04.2011, 20:40:18
Powód edycji: [Ociu]: poprawiłem bbCode
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
fiasko
post
Post #2





Grupa: Zarejestrowani
Postów: 243
Pomógł: 1
Dołączył: 1.06.2010

Ostrzeżenie: (0%)
-----


nie za bardzo rozumiem jak działa ta metoda .

[JAVASCRIPT] pobierz, plaintext
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2.  
  3. <html>
  4.  
  5. <head>
  6.  
  7. <meta http-equiv="Content-type" content="text/html; charset=utf-8">
  8.  
  9. <meta http-equiv='cache-control' content='no-cache'>
  10.  
  11. <link rel="stylesheet" href="style.css" type="text/css">
  12.  
  13. </head>
  14.  
  15. <body>
  16.  
  17. <div id="loading"><img src="images/loading.gif" width="20" height="20" border="0"></div>
  18.  
  19. <div id="content"> </div>
  20.  
  21. <script type="text/javascript" src="script/jquery-1.4.4.min.js"></script>
  22.  
  23. <script type="text/javascript" >
  24.  
  25. // Accepts a url and a callback function to run.
  26. function requestCrossDomain( site, callback ) {
  27.  
  28. // If no url was passed, exit.
  29. if ( !site ) {
  30. alert('No site was passed.');
  31. return false;
  32. }
  33.  
  34. // Take the provided url, and add it to a YQL query. Make sure you encode it!
  35. var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from html where url="' + site + '"') + '&format=xml&callback=?';
  36.  
  37. // Request that YSQL string, and run a callback function.
  38. // Pass a defined function to prevent cache-busting.
  39. $.getJSON( yql, cbFunc );
  40.  
  41. function cbFunc(data) {
  42. // If we have something to work with...
  43. if ( data.results[0] ) {
  44. // Strip out all script tags, for security reasons.
  45. // BE VERY CAREFUL. This helps, but we should do more.
  46. data = data.results[0].replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
  47.  
  48. // If the user passed a callback, and it
  49. // is a function, call it, and send through the data var.
  50. if ( typeof callback === 'function') {
  51. callback(data);
  52. }
  53. }
  54. // Else, Maybe we requested a site that doesn't exist, and nothing returned.
  55. else throw new Error('Nothing returned from getJSON.');
  56. }
  57. }
  58.  
  59. requestCrossDomain('http://xxx.pl/gadzet/content.php', function(results) {
  60. $('#kontener').html(results);
  61. });
  62.  
  63.  
  64. </script>
  65.  
  66.  
  67. <div id="kontener"></div>
  68.  
  69. </body>
  70.  
  71. </html>
[JAVASCRIPT] pobierz, plaintext



Jaką rolę odgrywa url http://query.yahooapis.com/v1/public/yql?q w tym skrypcie ? W ogóle nie za bardzo czaję o co tu biega. Wiem tylko, że działa gdy jest link do innej strony.

Jak w stronie dam tylko np. echo "test"

To i tak mam pusto.
Powód edycji: [Ociu]: poprawiłem bbCode
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 10.10.2025 - 00:12