jQuery.ajax post从select标记返回从onchange事件调用的页面的整个html

jQuery.ajax post returning whole html of the page called from onchange event from a select tag

本文关键字:调用 html 事件 onchange post ajax select 返回 jQuery      更新时间:2023-09-26

我想使用ajax将值从js文件发布到magento中的phtml文件,基本上,问题出在成功时,它会用页面的html代码来警告,从doctype开始直到结束。我想得到正确的值,因为我需要在通过PHP调用的一个magento函数中使用它。

这是我在更改时调用的函数:

function getsingproduct(id)
{
var str = 'product' + id;
var currentselecteditem;
ele = document.getElementById("product" + id);
currentselecteditem = ele.options[ele.selectedIndex].value;
jQuery.ajax({
    type: 'post',
    data: {
        curr_item: currentselecteditem
    },
    success: function (data) {
        jQuery('#testing').text(data);
        alert('data ' + data);
    },
});
}

下面是一些javascript代码:

$.ajax({
            type:"POST",
            url: "new_prob_submit.php", 
            data: {
    curr_item: currentselecteditem
},
            dataType: "json",
            success:function(data){
                 alert(data);
            }
        });```