In wordpress request.open('GET', 'data.json',true); not working! why?
-
Hi i am making a WordPress plugin that can bring the names of products from json file if someone writes products name into the search bar. But i think data.json is not getting by Ajax in WordPress. its path defining syntax error i guess.
$.getJSON('data.json', function(data)
following is complete scripting code and it was working fine in PHP website but not in WordPress.:
jQuery('#search').keyup(function(){ var searchField = jQuery('#search').val(); var myExp = RegExp(searchField,"i"); jQuery.getJSON('data.json', function(data){ var output= '<ul class="SearchResult">'; jQuery.each(data, function(key, val){ if((val.name.search(myExp) != -1) || (val.category.search(myExp) != -1)){ output += '<li>'; output += '<h2>' + val.name + '</h2>'; output += '<img src="images/'+val.image+'.jpg" alt="sorry for image"/>'; output += '<p>' + val.category + '</p>'; output += '</li>'; } }); output += '</ul>'; jQuery('#update').html(output); }); });
- The topic ‘In wordpress request.open('GET', 'data.json',true); not working! why?’ is closed to new replies.