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. 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.
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. 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());
in the error
part?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.