Jump to content
Vladimir

mJSONP.Request problem

Recommended Posts

Hello!!
I have some problem and I'm trying to fix it. I raised my REST server and when I sent the request mJSONP.Request ('http://93.87.76.76:8080/drzave'); I persistently get the answer: Uncaught SyntaxError: Unexpected token <[line # 1]. Please, some can help me to solve the problem? At this address can see how the server response looks. Thanks a lot!

Share this post


Link to post
Share on other sites

Best way to get that JSON is by reading the contents with a normal TW3HttpRequest and converting it to a variant:
 

uses
...
  SmartCL.Net.Http,
  System.Json;

...

var JsonResponse: Variant;
begin
  var Req:=TW3HttpRequest.Create;
  Req.OnDataReady := procedure(Sender: TW3HttpRequest)
    begin
      JsonResponse := JSON.parse(Sender.ResponseText);
      for var i:=0 to Length(JsonResponse.drzave)-1 do
        WriteLn(JsonResponse.drzave[i].naziv);
    end;
  Req.Get('http://93.87.76.76:8080/drzave');

 

Share this post


Link to post
Share on other sites

Sorry, maybe I'm boring, but only one more problem. When I performed in the Smart Mobile Studio, everything worked right, but when I run it in a browser (like Chrome), I get the following error messages and nothing is done .

Failed to load http://93.87.76.76:8080/drzave: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

VM62:1 Uncaught SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Object.W3Button1Click.Req$1.OnDataReady (index.html:16974)
    at Object.HandleReadyStateChange (index.html:17162)
    at XMLHttpRequest.<anonymous> (index.html:396)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×