简体   繁体   English

joomla ajax POST不发布

[英]joomla ajax POST not posting

Running Joomla 3.5.1 and I want to have an ajax call to pull data from another server, this works in another environment without any problem but cannot get it to work in Joomla. 运行Joomla 3.5.1,并且我想进行ajax调用以从另一台服务器提取数据,这可以在另一种环境中正常工作,但不能使其在Joomla中工作。 I found where I had to change $ to jQuery so the updates to the div work and the ajax url appears to work however there is no JSon data being sent for the post and therefore nothing sent back. 我找到了必须将$更改为jQuery的地方,以便对div的更新工作和ajax URL似乎可以正常工作,但是没有为该帖子发送JSon数据,因此也没有发送回去。

function GetProduct(ID) {
jQuery('#div_Options').text('');
var dataObj = "{\"PCID\": \"" + ID + "\"}";
try {
    jQuery.ajax({
        type: "POST",
        url: 'http://server.com/ajax/productoptions.asmx/GetTest',
        contentType: "application/json; charset=utf-8",
        crossDomain: true,
        dataType: "json",
        data: dataObj,
        cache: false,
        success: function (outData) {
            $("#div_Options").text(outData.d);
        },
        error: function (outData, msg) {
            jQuery("#div_Options").text('Ajax Error - ' + msg.toString());
        }
    });
}
catch (err) {
    jQuery("#div_Options").text('Code Error');
}

} }

Do I need to create a module or is there a simple fix for this? 我需要创建一个模块,还是有一个简单的解决方案?

If Ajax is working in principle, then the problem most likely lies with your data field. 如果Ajax原则上工作,那么问题很可能出在您的data字段上。 Check if that field contains the right information as expected by the remote server. 检查该字段是否包含远程服务器期望的正确信息。 Also, what do you get when you do alert(msg.toString()); 另外,执行alert(msg.toString());会得到什么? in the error part? error部分?

Doing it in a module will not solve your problem - the code is already working. 在模块中执行此操作不会解决您的问题-代码已在工作。 It's just that the data is field is most likely wrong. 只是data字段很可能是错误的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM