PHP로 JSON-POST-Request를 읽으려고했지만 다음 오류가 발생합니다. 여기PHP가 JSON-POST-Request를 읽고이를 다시 보내십시오.
Request failed: parsererror
내 코드
<script type="text/javascript" charset="utf-8" src="resources/js/model/Product.js"></script>
<script>
function getdetails(){
var p = new Product(15,11.5,"Pizza Test","P");
var z = new Product(68,1.5,"Zutate Test","Z");
p.addOneProduct(z);
var request = $.ajax({
type: "POST",
url: "yb_test_post.php",
dataType: "json",
data: JSON.stringify(p)
});
request.done(function(msg) {
$("#msg").html(" Post parameter are: <br/>"+msg);
});
request.fail(function(jqXHR, textStatus) {
alert("Request failed: " + textStatus);
});
}
</script>
내 PHP 코드, 난 POST 요청을 읽고 즉시
<table>
<?php
foreach ($_POST as $key => $value) {
echo "<tr>";
echo "<td>";
echo $key;
echo "</td>";
echo "<td>";
echo $value;
echo "</td>";
echo "</tr>";
}
?>
</table>
내가 뭘 잘못 인쇄하려고?
Product.js
function Product(id, price, name, type){
this.id = id;
this.price = +price;
this.totalPrice = +price;
this.name = name;
this.type = type;
this.products = [];
var self = this;
this.addOneProduct = function(oneProduct){
self.products.push(oneProduct);
self.totalPrice= self.totalPrice+oneProduct.price;
};
}
'제품'이란 무엇입니까? –