【发布时间】:2015-08-13 05:53:59
【问题描述】:
更新
问题解决了,看来我是傻了,引用title元素后忘记放.value了。
我已经使用 ajax 几个月了,之前从未遇到过这样的错误。
我正在创建一个 formData 数组并使用 ajax 将其传递给一个 php 脚本,就像我以前做过很多次一样,但是我现在遇到了那个奇怪的错误。
这可能与我的 formData 有关吗?我看不出有什么不同,因为它与我以前的做法没有什么不同。
任何帮助都会很棒,谢谢!
//This function will add the product and its details to the cart.
function addToCart(e)
{
//alert("CLick");
calculatePrice();
//Get the product ID from the URL
var id = getParameterByName('productID');
alert(id);
//Get the title.
var title = document.getElementById('title');
//Get the qty.
var qty = document.getElementById('qty').value;
//Get the weight.
var weightList = document.getElementById('weightList');
var weightText = weightList.options[weightList.selectedIndex].text;
//alert("Text: " + weightText);
var weightValue = weightList.options[weightList.selectedIndex].value;
//alert("Val: " + weightValue);
formData = {"ID" : id, "SRC": "", "Title" : title, "Qty" : qty, "Weight" : weightText, "Totalprice" : totalPrice, "Singularprice" : weightValue, "Action" : "Add"};
$.ajax(
{
url: 'manipulateCart.php',
type: "POST",
data: formData,
success: function(data)
{
alert("cc");
//document.getElementById('content').innerHTML = "";
//$('#content').append(data);
},
error: function(xhr,err)
{
alert("Error: " + xhr + " " + err);
}
});
}
【问题讨论】:
-
weightText和weightValue他们会完美吗? -
嗨,weightText 返回如下:110g Bag 和 weightValue 返回如下:3.00。会不会和 weightValue 上的 double 值类型有关?
标签: javascript php ajax