Re: [chicagoboss] Ajax call to get JSON file with controller

44 views
Skip to first unread message

chan sisowath

unread,
Dec 11, 2015, 9:34:04 PM12/11/15
to chica...@googlegroups.com
hi, 
from doc:
{output, Output::iolist(), Headers::proplist()}

Skip views altogether and return Output to the client while setting additional HTTP Headers.

in your case, should be:

index('GET', []) ->
 {ok,Data} = file:read_file("./ln.json"),
 {output,Data, [{"Content-Type","application/j-son;charset=UTF-8"}]}.
 
chan.


2015-12-12 5:07 GMT+08:00 Mert Öztürk <asksome...@gmail.com>:
Hello,

I am struggling to get my json file through controller and get action. I tried with this below;

index('GET', []) ->
 {ok,Data} = file:read_file("./ln.json"),
 {json,Data}.

and also with;

index('GET', []) ->
 {ok,Data} = file:read_file("./ln.json"),
 {json,binary_to_list(Data)}.

Clientside:

$.ajax({
     type: "GET",
     async: false,
     beforeSend: function(x) {
      if(x && x.overrideMimeType) {
         x.overrideMimeType("application/j-son;charset=UTF-8");
      }
     },
     dataType: "json",
     success: function(data){
       JSON = data
     }
});

I can read json file but couldnt send json data to client. Help will be appreciated.

Thanks
Mert


--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
Visit this group at http://groups.google.com/group/chicagoboss.
To view this discussion on the web visit https://groups.google.com/d/msgid/chicagoboss/f20d5420-8732-4773-ad16-fd8a73577df6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mert Öztürk

unread,
Dec 12, 2015, 3:20:44 AM12/12/15
to ChicagoBoss
Thanks Chan it is working!

12 Aralık 2015 Cumartesi 04:34:04 UTC+2 tarihinde mihawk yazdı:
Reply all
Reply to author
Forward
0 new messages