2011-09-11 4 views
1

콜백 페이지 (php)에서 데이터를 가져와 jQuery 모바일으로 html div에로드하려고합니다. 사용자가 다른 div를 클릭하면 이런 일이 발생합니다. #home-button 이벤트 및 #displayContent 내용이에 넣어되어야 사업부를 트리거해야 사업부는 어디에서 실제로 가지고 무엇jQuery 모바일로 div를 클릭하여 페이지 콘텐츠를 요청하는 방법은 무엇입니까?

$.('#home-button').bind('vclick', function(e) { 
    $.get('homeCallback.php',function(data){ 
     $('#displayContent').append(data).trigger('create'); 
    },'html'); 
}); 

입니다. 요청도 몇 가지 매개 변수를 전달 할 수 있어야한다 . homeCallback.php?param=1처럼하지만 post 메소드를 사용할 수도 있습니다. 콜백은 html 일 필요는 없으며, 콜백 PHP 스크립트가 JSON 데이터 또는 아무것도 제공하지 않을 수도 있습니다.

나는 JS 균열이 아니므로이 문제를 해결하는 데 문제가 있습니다. 당신의 도움을 주셔서 감사합니다! 지금까지 ..

<?php 
if(isset($_GET["option1"])) 
    echo "option1"; 
if(isset($_GET["option2"])) 
    echo "option2"; 

$(document).ready(function() { 
    $.ajaxSetup ({ 
     cache: false 
    }); 

    var ajaxLoader = '<img src="images/ajax-loader.gif" alt="loading.." />'; 
    var loadUrl = "homeCallback.php"; 

    $('#home-button1').click(function(){ 
     $('#displayContent').toggle('fast', function() { 
      $(this).html(ajaxLoader); 
      $(this).toggle('fast', function() { 
       $.get(loadUrl + '?option1',function(data){ 
        $('#displayContent').html(data); 
       },'html');     
      }); 
     }); 
    }); 

    $('#home-button2').click(function(){ 
     $('#displayContent').toggle('fast', function() { 
      $(this).html(ajaxLoader); 
      $(this).toggle('fast', function() { 
       $.get(loadUrl + '?option2',function(data){ 
        $('#displayContent').html(data); 
       },'html');     
      }); 
     }); 
    }); 
}); 

그리고 이것은 homeCallback.php 단순히 무엇이다 :

편집 : 그래서 난 내 자신에 대한 해결책을 발견했다.

+0

괜찮습니다. 특히 응용 프로그램에 페이지를 추가하려는 경우 특히'$ (document) .ready'보다는 적절한 jQM 페이지 이벤트를 사용하는 것이 좋습니다. – Ben

답변

0
$.('#home-button').bind('click', function() { 
    $.ajax({ 
     url: "homeCallback.php", 
     type: "POST", 
     data: ({param: 1, param2: 2}), 
     success: function(html){ 
      $("#displayContent").html(html); 
     } 
    }); 
}); 
+0

답변 해 주셔서 감사합니다.하지만 혼자 해결책을 찾았습니다. 여기에 게시 할 것입니다 .. – dnl

관련 문제