1

Hi guys so i made a code that parses a CSV file into a JSON ARRAY with PHP. So when you go to this URL you get the PHP output:

http://www.jonar.com/portal/mynewpage.php

Now i used this code to append my JSON ARRAY to HTML but now things have changed since i am using PHP i am not sure how to use it and what to do differently.

Also my ajax call is always empty which is weird..

$.ajax({
    type: 'GET',
    url: 'http://www.jonar.com/portal/mynewpage.php',
    dataType: 'jsonp',
    success: function(response) {
        alert(response);
    }
});

I used this to append my JSON ARRAY but now if i can get the response do i use the same code or will it have to be altered?

  $.each(results.data.slice(1), // skip first row of CSV headings
            function(find, data) {
                var title = data.title;
                var link = data.link;
                var date = data.date;
                var type = data.type;
                var where = data.where;
                var priority = data.priority;
                if (priority == '1') {
                    $('ul.nflist').prepend($('<li>', {
                        html: '<a href="' + link + '">' + title + '</a> ' + ' ' + '<span class="category">' + type + '</span>'
                    }));
                } else if (where == 'pp', 'both') {
                    $('ul.nflist').append($('<li>', {
                        html: '<a href="' + link + '">' + title + '</a> ' + ' ' + '<span class="category">' + type + '</span>'
                    }));
                }
            });

the reason i used PHP is to avoid cross domain issue

Thanks for the help guys!

Raja
  • 305
  • 2
  • 15
  • 1
    The first thing is, the request is not a JSONP request. – Praveen Kumar Purushothaman Oct 05 '15 at 13:49
  • 2
    Are you grabbing data from that is on the same domain as url in the ajax call? – PT_C Oct 05 '15 at 13:50
  • i assumed that you could call a `PHP` that has `JSON ARRY` with `JSONP` – Raja Oct 05 '15 at 13:50
  • @PT_C no the data is on a different domain – Raja Oct 05 '15 at 13:51
  • interesting... lets say the PHP file is hosted on my domain and that PHP file gets the data from different domain would that work? @PT_C I think that works but i need to figure out why my ajax call does work and how to append the data once i have it – Raja Oct 05 '15 at 13:52
  • 1
    Yes. I usually use an ajax call to grab a locally hosted jsp file which uses a java servlet to call a java file to read in and parse the data. You may be able to use [crossDomain](http://stackoverflow.com/questions/16989505/jquery-cross-domain-ajax) as part of your ajax – PT_C Oct 05 '15 at 13:54
  • @PT_C okay so i will host the `PHP` file on my `DOMAIN` and that `PHP `will get the data and transform it into `json `then i will use an `ajax request `with `datatype:json` to get my data correct? – Raja Oct 05 '15 at 14:00
  • 1
    That is the way I do it with Java, yes. – PT_C Oct 05 '15 at 14:04

0 Answers0