I'm pulling a module from our Joomla site to host onto our local servers and put back into Joomla as an iframe. I've gotten the source code, set up the database to mirror that of the Joomla. When I try to do a search, I get this error:
Uncaught TypeError: Cannot read property 'HTML' of undefined
This is the js that is being called:
// Functon to perform the actual search based on Method
function displayMethod(searchText, pageNumber) {
var jqxhr = jQuery.ajax("index.php?option=com_ppsearchusd&view=ppsearchusd&task=displayMethod&format=json&searchText=" + searchText + "&pageNumber=" + pageNumber)
.success(function (result) {
jQuery('#searchResults').html(result.data.HTML);
jQuery('#alphaDiv').css('display', 'none');
/*jQuery('#searchResults').html(result.data.HTML);
jQuery('#searchResult-detail').css('display', 'none');
jQuery('#searchResults').css('display', 'block');
jQuery('#alphaDiv').css('display', 'none');*/
jQuery('#searchResults #search-pagination').pagination({
items: result.data.items,
itemsOnPage: result.data.itemsOnPage,
currentPage: result.data.currentPage,
cssStyle: 'compact-theme',
hrefTextPrefix: 'javascript:',
onPageClick: function(pageNumber, event){
var searchText = jQuery('#searchTXT').val();
updateSearch(searchText, pageNumber);
}
});
})
.fail(function (jqxhr) {
alert('status:' + jqxhr.status);
});
}
If I copy the ajax url and append it (on my local machine) url, it get a blank page, whereas on the actual site, I do get a success JSON response. I'm sure I'm missing something that it is suppose to reference but I'm not sure what. I'm still relatively new to AJAX and js. I'm reviewing the original code and I'm not sure where "HTML" within the
jQuery('#searchResults').html(result.data.HTML);
is defined but I don't see.
console.log(JSON.stringify(result));
say if write on the line immediately after .success? Are you serving data from php usingecho new JResponseJson($result);
? <--what does that$result
look like?...
? Where did you write theecho new JResponseJson($result);
? Can we see that part of your code? What does the data structure look like that you are passing toecho new JResponseJson();
? I'd like to know where theHTML
key is in the data.