This is my first time calling AJAX from within jQuery so please bear with me here. I have a JSON file where I have formatted all of my data, and would like to simply call the JSON file and append some of the data to my HTML.

I should let everybody know that I am using WordPress as a backbone for the site, though the PHP-based framework is not being utilized at all to my knowledge in this call, I did try and write out my URL to make sense within the jQuery. All of the id’s in the slugArray array exist within my HTML.

OK! So:

JSON file can be seen here: http://bmgz.rtcgraphics.com/../ajax-call-not-working-in-wp-based-site/wp-content/themes/bmgz/data/whatwedo.js

jQuery:

var slugArray = [
    '#project-management',
    '#economic-incentives',
    '#site-selection',
    '#stakeholder-engagement-and-events',
    '#lobbying-and-advocacy',
    '#public-policy-and-issues-management',
    '#digital-communications',
    '#event-and-trade-show-materials',
    '#presentation-and-print-design'
]
function getWWD(){
    for (i=0; i<=slugArray.length; i++) {
        var selection = slugArray[i];
        $(selection).click(function(){
            $.getJSON('../ajax-call-not-working-in-wp-based-site/wp-content/themes/bmgz/data/whatwedo.js', function(result){
                alert("It works!");
                var entry=result.whatwedo[0].id;
                console.log(entry);
                });
            });
        }
    };
getWWD();

When I run this, I don’t get anything, not even my alert. I was getting a 404 error when I typed in the URL wrong for the $.getJSON request, so I know the computer is reading it at least partly. Thanks guys! I appreciate any input!

Read more here: AJAX call not working in WP based site


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , , ,

Wordpress related questions and answers: