0

I've built a function that GETS a JSON array and returns it and I've done this in a number of places without trouble. However, I'm trying to add new ones to some new pages on my website and the site is giving me a 404 error and messing up by url requested:

When you visit the wrong URL it displays: https://theprepared.life/earthquakes/%E2%80%8Bhttps:/theprepared.life/data/earthquakes-today.json

That is returned from the following script:

<table id="table1">
    <thead>

        <tr>

            <th>Name</th>

            <th>Magnitude</th>

            <th>Alert</th>

            <th>Strength</th>
        </tr>

    </thead>

    <tbody></tbody>

</table>


<script type="text/javascript">

    jQuery(document).ready(function($) {

        var table = $("#table1").DataTable({

            "bPaginate": true,

            "bLengthChange": false,

            "bFilter": true,

            "bInfo": true,

            "columns": [

                { "width": "37.5%" },

                { "width": "27.5%" },

                { "width": "17.5%" },

                { "width": "17.5%" }

            ],

            "order": [[ 1, "asc" ]]

        });

        jQuery.getJSON("​https://theprepared.life/data/earthquakes-today.json", function(data) {
            var count = (data.metadata.count);
            console.log(count);
            $.each(data.features.properties, function(index, i) {

                var row = "<tr><td><a target='_blank' href=test.html>"+i.title+"</a></td><td>"+i.mag+"</td><td>"+i.alert+"</td><td>XYZ</td></tr>";

                table.row.add($(row)).draw();
            });
        });

});

</script>

This works in a dozen other places but for some reason the URL is busted and I've already searched the entire myphpadmin for the %E2%80% with no results found. Any ideas?

3
  • Hey Tom, thanks for helping. I'm not following - the above code is the entire page I'm trying to include inside the wordpress page. the jQuery.getJSON when trying to get that URL it fails and says 404 with the error: theprepared.life/earthquakes/%E2%80%8Bhttps:/theprepared.life/… – Xeverus Jul 4 '18 at 22:41
  • hmmm other than the coincidence the site is running WordPress, is there anything non-JS about the problem? This looks like a pure jQuery problem, not a WordPress issue. Additionally, have you tried running the getjson call from the dev tools console? – Tom J Nowell Jul 4 '18 at 22:42
  • I'm rebuilding it now just stand alone from Wordpress altogether. Will see if that was the issue. – Xeverus Jul 4 '18 at 22:47
0

If I run a curl command:

curl ​https://theprepared.life/data/earthquakes-today.json

I get back the json object correctly. So your server work properly.

So unless from a different origin, when you running $.getJSON() call, you only need to submit data/earthquakes-today.json as the url, instead of the entire url, which caused the 404 error.

$.getJSON("data/earthquakes-today.json", function(data) {
   // rest of the code here
});

BTW, %E2%80%8B is UTF-8 code for <, You should check your server for the 404 page script or redirect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.