2013-09-25 6 views
0

사용자가 버튼 (+)을 클릭하면 div에 새 필드를 삽입하고 싶습니다.AJAX로 PHP 코드 추가하기

<?php 
$sql = "SELECT nome, codigo FROM ref_bibliograficas"; 
$result = mysql_query($sql) or die (mysql_error()); 
echo ("<select class='autocomplete big' name='ref_bib_0' style='width:690px;' required>"); 
echo ("<option select='selected' value=''/>"); 
while($row = mysql_fetch_assoc($result)){ 
echo ("<option value=" . $row["codigo"] . ">" . $row["nome"] . "</option>"); 
echo ("</select>"); 
mysql_free_result($result); 
?> 

그래서, 내가 AJAX와 함께 필드를 삽입하는 방법을 모르는 :

텍스트 필드의 코드는 점이다.

나는 onclick 함수를 jQuery로 구성했다. 누구든지 제발 도와 주실 래요?

감사합니다.

답변

1

당신이 찾고있는 것은 jQuery .load() 기능입니다. 당신이 APPEND 새로운 분야로합니다

$('#addButton').click(function(){   // Click event handler for the + button. Replace #addButton wit the actual id of your + button 
    $('#myDiv').load('yourphppage.php'); // This loads the output of your php page into your div. Replace #myDiv with the actual id of your div 
}); 

:

http://api.jquery.com/load/는 다음 자바 스크립트 코드의 모양은 당신이 당신의 사업부에 추가 할 당신의 PHP 페이지 출력 원하는 HTML을 가지고 당신의 사업부는, 당신은 다음을 수행해야합니다

$('#addButton').click(function(){ 
    $.post('yourphppage.php', function(data) { 
     $('#myDiv').append(data); 
    }); 
}); 
0

아약스 접근을

$(document).ready(function(e) 
{ 
    $('#plus-button').click(function(e) 
    { 
    $.ajax(
    { 
    url: "PHP-PAGE-PATH.php", // path to your PHP file 
    dataType:"html", 
    success: function(data) 
    { 
     // If you want to add the data at the bottom of the <div> use .append() 

     $('#load-into-div').append(data); // load-into-div is the ID of the DIV where you load the <select> 

     // Or if you want to add the data at the top of the div 

     $('#load-into-div').prepend(data); // Prepend will add the new data at the top of the selector 
    } // success 
    }); // ajax 
    } 

});