1

I am trying to render several components - but my service is a from a lamp stack. -- after rendering the component I try and do an ajax call -- I can see the call comes back in the network console -- but the alert is never triggered -- I've tried the ajax approach as well.

componentDidMount() {
    $.getJSON("http://localhost/react4/sample.json?callback=?", function(result){
       //response data are now in the result variable
       alert(result);
    });
}

//sample.json

[{"date": "2nd Aug"}]

network packet screenshot -- call and response from localhost enter image description here

success from network packet enter image description here

localhost - lamp stack running -- dummy json coming through enter image description here

code on reactjs -- getjson doing the callback

enter image description here

no console error - no alert enter image description here

adding console flags enter image description here

only check1 appears -- its as if the response never comes back enter image description here

Matthew Herbst
  • 29,477
  • 23
  • 85
  • 128
The Old County
  • 89
  • 13
  • 59
  • 129
  • 1
    Error messages in your console? – TimoStaudinger Aug 23 '16 at 19:26
  • To be sure: you are running a local LAMP stack to support using localhost, right? – Matthew Herbst Aug 23 '16 at 19:58
  • 1
    Possible duplicate of [jQuery Ajax request from local filesystem (Windows file:///)](http://stackoverflow.com/questions/5469440/jquery-ajax-request-from-local-filesystem-windows-file) – Matthew Herbst Aug 23 '16 at 20:00
  • -- I don't think its a duplicate of the localfile system @MatthewHerbst -- php wamp localhost is running. – The Old County Aug 23 '16 at 21:06
  • @TimoSta -- added screenshots – The Old County Aug 23 '16 at 21:06
  • @TimoSta no errors to speak of -- warnings due to unused variables -- but no errors... – The Old County Aug 23 '16 at 21:07
  • @MatthewHerbst - alright well turning it from a .json to a .php and adding that header -- and echoing it out - yes that works as a regular json call - header('Access-Control-Allow-Origin: *'); --- but why wasn't the jsonp callback working? Its a reactjs project that's why I wondered if the different port was causing another issue – The Old County Aug 23 '16 at 21:33
  • @MatthewHerbst - so why did the jsonp method I had in place not work? – The Old County Aug 23 '16 at 23:01
  • 1
    So, first off that the port is the domain of the server. React - or any other front-end framework, doesn't care what port you are running on. I'll be the first to admit that my knowledge of jsonp is limited. However, my first guess: are you sure your server actually supports jsonp? It might simply never be calling the callback function. – Matthew Herbst Aug 23 '16 at 23:14
  • -- well the react is on a node localhost at "http://localhost:3000/" -- and the wamp is on localhost -- which I assume to be 8080 by standard? -- so its odd that I can see the call come back ok in the network console -- but its as if it doesn't get called back – The Old County Aug 23 '16 at 23:16

0 Answers0