0

I am currently doing an exercise on jQuery, Mockjax, Ajax and JSON. but it seems that Mockjax doesn't work perfectly. Here is what I am trying:

function mockJaxTest(param){
  var url_pos = "http://localhost:8080/project/dashboard/"+param+".htm";
  $.mockjax({
     url: url,
     dataType: 'json',
     contentType: 'application/json',
     proxy: "resources/mocks/data-pos.json"
  });

  $.getJSON(url_pos, function(data) {
    if (data) {
      alert('SUCCESS');
    } else {
      alert('FAILED');
    }
  });
}

What am I doing wrong?

hnacer
  • 3
  • 4
  • what is the error ? – Muhammad Usman Apr 24 '18 at 10:16
  • change proxy: "resources/mocks/data-pos.json" to proxy: "/resources/mocks/data-pos.json" – RAHUL S R Apr 24 '18 at 10:25
  • There is no error displayed. But by adding alert message, I get the message "FAILED". Moreover the file 'data-pos.json' is still empty. – hnacer Apr 24 '18 at 10:28
  • @RAHULSR I changed this but didn't work. – hnacer Apr 24 '18 at 10:58
  • This could be all sorts of things. For example, if there is _any_ syntax error in the JSON file itself then `$.getJSON()` fails silently (no error). I would add some additional handlers for errors, because right now you can't see what the message is when the call fails. [Read the docs](http://api.jquery.com/jquery.getjson/) and try adding a `.fail()` handler at the end to see the error! Also, please post your JSON file here so we can help! – Jordan Kasper May 17 '18 at 12:10

0 Answers0