양식을 가져야하는 데이터가 일부 있는데 아약스로 처리하려고합니다. 단추의 onclick 이벤트에 응답하는 함수가 있습니다. 버튼을 클릭하면 방화 광에서 일부 게시물 데이터가 있지만 PHP 스크립트에 도달하지 못합니다. 누가 잘못되었는지 알아?Ajax는 양식 데이터를 PHP 스크립트에 게시하지 않습니다.
JS :
function newItem() {
var dataSet = $("#createItem :input").serialize();
confirm(dataSet); //Below this code box is the output of this variable to check whether it is filled or not
var request = $.ajax({
type: "POST",
url: "/earnings.php",
data: dataSet,
dataType: "json"
});
request.done(function(){
$('.create_item').children(".row").slideUp('100', 'swing');
$('.create_item').children("h2").slideUp('100', 'swing');
confirm("succes");
});
request.fail(function(jqXHR, textStatus) {
confirm("Request failed:" + textStatus);
});
}
셋 결과 폼은 completly에 충전했을 때 id=123&date=13-09-2013&amount=5&total=6%2C05&customer=HP&invoicenumber=0232159&quarter=1&description=Test
PHP :
<?php
include('includes/dbconn.php');
function clean_up($string){
$html = htmlspecialchars($string);
$string = mysql_real_escape_string($html);
return $string;
}
if($_POST){
$date = clean_up($_POST['date']);
$amount = clean_up($_POST['amount']);
$total = clean_up($_POST['total']);
$customer = clean_up($_POST['customer']);
$invoicenumber = clean_up($_POST['invoicenumber']);
$quarter = clean_up($_POST['quarter']);
$description = clean_up($_POST['description']);
$sql = ("INSERT INTO earnings (e_date, e_amount, e_total, e_customer, e_invoicenumber, e_quarter, e_description)
VALUES ($date, '$amount', '$total', '$customer', $invoicenumber, $quarter, '$description')");
echo $sql;
if($mysqli->query($sql) === true){
echo("Successfully added");
}else{
echo "<br /> \n" . $mysqli->error;
}
}
?>
형태가 함께 AJAX없이 잘 작동하지만 그냥 작동하지 않습니다.
귀하의 도움에 감사드립니다!
'print_r ($ _ POST);'check under net> 응답 i n firebug –
url : "/earnings.php", ' – DontVoteMeDown
경로가 맞고 페이지가 PHP 스크립트로 이동하지 않고 새로 고침을하기 때문에 방화 광에서 PHP 응답을 볼 수 없습니다. html 형식. – Tom