문제

나는 이것을 어떻게 해야할지 전혀 모른다. 그래서 나는 단지 계속해서 물어볼 것이다.

내가하고 싶은 것은 외부 파일 (send.php)이라는 PHP 스크립트로 div의 내용을 업데이트하는 것입니다.

그래서 나는 다음과 같은 div가 있습니다.

<div class="classname">

</div>

또한이 send.php 파일에 데이터를 게시 한 다음 PHP 스크립트의 결과가 무엇이든 해당 DIV를 업데이트하고 싶습니다. 이 작업을 수행 할 수 있습니까?

도움이 되었습니까?

해결책

간단한 ajax 호출의 경우 일반적으로 사용을 선호합니다 $ .load 문법은 매우 간결합니다. 매개 변수를 객체 (키/값 쌍)로 전달하면 게시물 요청을 사용하게됩니다.

<a href="no-script.php" class="something">Click!</a>

$(document).ready(function() {
    $('a.something').click(function(e) {
        //prevent the href from being followed
        e.preventDefault();

        //inject div.classname with the output of send.php
        $('div.classname').load('send.php', {param1: 'foo', param2: 'blah'});
    });
});

게시물이 필요하지 않은 경우 매개 변수를 쿼리 문자열로 추가 할 수 있습니다.

$('div.classname').load('send.php?param1=' + param1 + '&param2=' + param2);

다른 팁

<a href="#">click</a>

<script>
    $(function() {
      $("#refresh").click(function(evt) {
         $("#classname").load("send.php?data=someData")
         evt.preventDefault();
      })
    })
</script>


<div id="classname">

</div>

읽을 일부 문서 :

  1. http://docs.jquery.com/ajax/jquery.post

전적으로! 보세요 이것 jQuery의 Ajax 기능을 사용하는 방법에 대한 지침을 게시하십시오. 그런 다음 전화하고 싶을 것입니다

$.(".classname").append("Whatever results you get");

Div를 채우기 위해.

행운을 빕니다!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top