Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [HTML][AJAX][PHP]Zdalnego servera na locahost strona mi nie działa, AJAX
silverwind
post 28.01.2015, 14:49:14
Post #1





Grupa: Zarejestrowani
Postów: 80
Pomógł: 0
Dołączył: 8.02.2013

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


Chciałem sprawdzić moją stronę z innego komputera. Używam zampp jako server. ustawiłem ip 192.168.0.3 . Udaje mi się wejść i strona działa tylko jak chce wykonać skrypt ,który jest wczytywany Ajaksem nic się nie dzieje. Nie zdalnie działa wszystko ok
to jest kod Ajax



if (window.XMLHttpRequest)
{
ObiektXMLHttp = new XMLHttpRequest(); }
else if (window.ActiveXObject)
{
ObiektXMLHttp = new ActiveXObject("Microsoft.XMLHTTP"); }

// druga część kodu
function getData(zrodlo, cel) {
if(ObiektXMLHttp)
{
var cel = document.getElementById(cel);
ObiektXMLHttp.open("GET", zrodlo);

ObiektXMLHttp.onreadystatechange = function()
{
if (ObiektXMLHttp.readyState == 4)
{
cel.innerHTML = ObiektXMLHttp.responseText;
}
}
// trzecia część kodu
ObiektXMLHttp.send(null); } }
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 6)
markuz
post 28.01.2015, 15:08:05
Post #2





Grupa: Zarejestrowani
Postów: 1 240
Pomógł: 278
Dołączył: 11.03.2008

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


Co konsola wypluwa? Podejrzewam problem z nagłówkami allow-access-control-origin..


--------------------
Go to the top of the page
+Quote Post
silverwind
post 28.01.2015, 19:14:49
Post #3





Grupa: Zarejestrowani
Postów: 80
Pomógł: 0
Dołączył: 8.02.2013

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


XMLHttpRequest cannot load http://localhost/strona/1.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.0.2' is therefore not allowed access. The response had HTTP status code 404.


co muszę zmienić by mi to działało
Go to the top of the page
+Quote Post
markuz
post 28.01.2015, 19:19:15
Post #4





Grupa: Zarejestrowani
Postów: 1 240
Pomógł: 278
Dołączył: 11.03.2008

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


w pliku 1.php tam gdzie zwracasz odpowiedź (na samym początku) dodaj:
  1. header('Access-Control-Allow-Origin: *');


Ten post edytował markuz 28.01.2015, 19:26:38


--------------------
Go to the top of the page
+Quote Post
silverwind
post 28.01.2015, 21:47:04
Post #5





Grupa: Zarejestrowani
Postów: 80
Pomógł: 0
Dołączył: 8.02.2013

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


GET http://localhost/strona/1.php Ajax.js:30
getData wydajnosc.php:52
onclick wydajnosc.php:1
XMLHttpRequest cannot load http://localhost/strona/1.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.0.2' is therefore not allowed access. The response had HTTP status code 404
teraz mam takie


Go to the top of the page
+Quote Post
markuz
post 28.01.2015, 21:58:49
Post #6





Grupa: Zarejestrowani
Postów: 1 240
Pomógł: 278
Dołączył: 11.03.2008

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


Pokaż zawartość pliku 1.php


--------------------
Go to the top of the page
+Quote Post
silverwind
post 28.01.2015, 22:09:57
Post #7





Grupa: Zarejestrowani
Postów: 80
Pomógł: 0
Dołączył: 8.02.2013

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


  1. ?php
  2. header('Access-Control-Allow-Origin: *');
  3. //$stara_wartosc = ini_set ( 'max_execution_time', 0 );
  4. error_reporting(0);
  5. $con = mysqli_connect("localhost","root","","my_db");
  6. if($con)
  7. // Check connection
  8. if (mysqli_connect_errno())
  9. {
  10. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  11. }
  12.  
  13.  
  14. //for($j=0; $j<5; $j++)
  15.  
  16. //{
  17. $stoper_start = time(true);
  18.  
  19.  
  20. usleep(10000);
  21. $query = "INSERT INTO osoby (`Imie`, `Nazwisko`,`Wiek`) VALUES ";
  22.  
  23.  
  24. for($i=0; $i<500000; $i++)
  25. {
  26. $query .= "('Ewa', 'Ciemała', '87'),";
  27.  
  28. }
  29.  
  30. $query = substr($query, 0, -1); // na końcu nie może być przecinka więc go ucinam
  31. mysqli_query($con,$query);
  32.  
  33.  
  34.  
  35. $stoper_stop = time(true); //koniec pomiaru
  36.  
  37. $wynik=bcsub($stoper_stop, $stoper_start,0);
  38. //$wynik_tab[$j] = array($wynik);
  39. //print_r($wynik_tab[$j]);
  40. //}
  41.  
  42.  
  43.  
  44.  
  45.  
  46. ?><p class="wynik"><h1> <?php echo $wynik; echo " sekundy" ?></h1></p>;
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. <?php
  55. mysqli_close($con);
  56. ?>
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 16.07.2025 - 07:40