가 아약스를 사용하려면 다음과 같이 HTML로 include
에 파일을 inclue PHP는 funcion을 사용할 수 있습니다 (</body>
태그 바로 앞에)
그런 다음 데이터 변수를 편집하여 데이터를 $ _POST로 보낼 수 있습니다. 이 스크립트가 PHP 스크립트에 보내는 데이터에 액세스하려면 $ _POST 변수를 호출하면됩니다. 예 : var2에 액세스하려면 PHP 스크립트 $ _POST [ 'var2']를 넣으십시오. 게시물 대신 GET을 사용하는 경우 PHP 스크립트에서 $ _GET [ 'var2']를 사용하여 해당 변수를 가져와야합니다.
var data = 'var1=value&var2=value2&var3=value3';
$.ajax({
type: "POST", //can be POST or GET
url: "URL_TO_SCRIPT_GOES_HERE.php",
dataType: "html", //or json
data: data, //data to send as $_POST to script
success: function(response) {
//Once data received, do this
alert(response);
},
error: function(response) {
}
});
데이터베이스 연결 라인은 PHP 파일에 저장해야합니다. jquery ajax 스크립트와 아무 관련이 없습니다.
아약스 호출을 실행하려면, 당신은 내가 (이 페이지로드로드) 여기에이 방법을 실행하거나 이벤트에 따라 자바 스크립트 함수에 넣어 그것을 호출 할 수 있습니다 :
function my_ajax_call() {
var data = 'var1=value&var2=value2&var3=value3';
$.ajax({
type: "POST", //can be POST or GET
url: "URL_TO_SCRIPT_GOES_HERE.php",
dataType: "html", //or json
data: data, //data to send as $_POST to script
success: function(response) {
//Once data received, do this
alert(response);
},
error: function(response) {
}
});
}
온 클릭 버튼 트리거 :
<a onclick='my_ajax_call()'>CALL AJAX</a>
그 코드는하지만 PHP를 위해 .PHP 확장 – Sam