Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 奇怪的错误:未捕获类型错误:非法调用ajax_Javascript_Php_Ajax - Fatal编程技术网

Javascript 奇怪的错误:未捕获类型错误:非法调用ajax

Javascript 奇怪的错误:未捕获类型错误:非法调用ajax,javascript,php,ajax,Javascript,Php,Ajax,更新 问题解决了,似乎我太笨了,在引用title元素后忘记输入.value 我已经使用ajax几个月了,以前从未遇到过这样的错误 我正在创建一个formData数组,并使用ajax将其传递给php脚本,就像我以前做过很多次一样,但是现在我遇到了一个奇怪的错误 它可能与我的formData有关吗?我看不出有什么不同,因为这和我以前做的没有什么不同 任何帮助都会很好,谢谢 //This function will add the product and its details to the

更新

问题解决了,似乎我太笨了,在引用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);
                }

            });

    }

此行中缺少
.value

 var title = document.getElementById('title').value;
                                              ^^^^^

您正在将
title
变量传递给formData对象。此变量包含
#title
元素,而不是该元素的值。将
.value
添加到
var title=document.getElementById('title')

结果:

var title=document.getElementById('title').value


更多信息:

weightText
weightValue
它们是否完美无瑕。?您好,weightText返回值为110g行李,weightValue返回值为3.00。这可能与weightValue上的双值类型有关吗?啊,是的,这就是原因,谢谢!我一定是冲着那条线忘了放。再次感谢,+1!