2014-05-14 1 views
0

나는 AJAX에 열광하고 있으며, 실제로는 곧 실제 방향을 배울 것이라고 맹세합니다. 그러나 지금 당장 필요한 것은 내부 브라우저 높이를 가져와 Google Maps Engine에 적절한 높이의지도를 요청할 수 있습니다. (실제로 Joomla에서 Google Maps 플러그인을 통해 요청을하는 중입니다. 클라이언트 측에서 어떻게 든 요청을 할 수 있다면 AJAX를 망칠 필요가 없을 수도 있지만 여전히 좋은 입문서가 될 것입니다. .)간단한 AJAX 쿼리에 대한 코드의 위치에 대한 단서가 필요합니다.

첫 번째 답변의 코드를 통합 한 작업 최소 문서를 함께 넣어서 기본 AJAX 설정을 파악하려고합니다. how to get screen width through php?. 나는 예제가 내가 요구할 것보다 다른 속성을 요구한다는 것을 알지만, 코드를 가능한 한 원본에 가깝게 유지하고있다. 내가하는 코드에 대해 완전히 명확하지 않다

어디 간다,하지만 분명히 그것은 http://allbluesdance.com/testajax.php에서이되지 않습니다 : 내가 단서를 사용할 수있는 바보 같은 구문 오류가 만들었어요 그래서하지 않는

<!doctype html> 
<html> 
<head> 
    <meta charset="utf-8" /> 
    <title>Test Ajax</title> 
</head> 
<body> 

    <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 

    <script> 
     var width = $(window).width(); 
     //This is ajax code which will send width to your php page in the screenWidth variable 
     $.ajax({ 
      url: "http://allbluesdance.com/testajax.php", //this will be your php page 
      data : {screenwidth:width} 
     }).done(function() { 
      $(this).addClass("done"); 
     }); 
    </script> 

(Yeah, it's running) 

    <!-- example.php code is here : --> 
    <?php 
     echo $width = $_REQUEST['screenwidth']; 
    ?> 

</body> 
</html> 

합니다.

덕분에, 드류

답변

0

난 당신이 AJAX 중 하나 GET 또는 POST를 통해 데이터를 가져 오는 방법을 지정할 필요가 있다고 생각합니다. 나는이 발췌 문장을 사용하고 있으며 그것은 나를 위해 작동합니다.

// fire off the request 

    var request = $.ajax({ 
     url: "/list/server.php", 
     type: "POST", 
     data: send_data 
    }); 

    // callback handler that will be called on success 
    request.done(function (response){ 
     // log a message to the console 
     console.log(response); 
    });