0

What's wrong with this code?

$.ajax({
         //url: 'http://ip.jsontest.com/',
        // url: 'http://ipinfo.io/json',
        //url: 'http://ip-api.com/json',
        url: 'http://www.onecert.com.br/json.asp',
        success: function(data) {       
        alert("OK");    
        },
        error: function(dataerror) {
        alert("NO");
        }
    });

I create a CLASSIC ASP that create a JSON (verified on online testers). If I tried any other URL on AJAX its works.. but with this CLASSIC ASP doesn't.

Classic ASP is created with JSON_2.0.2.asp.

<!--#Include File="JSON_2.0.2.asp"-->

<%
Response.ContentType = "application/json"

Dim member
Set member = jsObject()

member("name") = "Daniel"
member("surname") = "Smith"
member("message") = "Hello"

member.Flush
%>

Why? (I'm a beginner)

I tried with Response.ContentType and without. Same Result.

Thanks for all repplies

http://jsfiddle.net/gwfcr5z8/

DANIEL
  • 515
  • 7
  • 20

2 Answers2

1

What is your Page Domain. Is it same as "http://www.onecert.com.br" if NO then This is the Problem of Cross Origin Policy and in Browser Console It will Display

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.onecert.com.br/json.asp. This can be fixed by moving the resource to the same domain or enabling CORS.

If this is the case, Please Refer Below Links

Can't get jQuery to get JSON from another domain (using JSONP)

jQuery getJSON works locally, but not cross domain

http://en.wikipedia.org/wiki/JSONP

Community
  • 1
  • 1
  • 1
    @daniel That is the problem but regardless of whether it is on the same box Chrome will still complain about the missing `Access-Control-Allow-Origin` HTTP header. If your client script runs from the same site just use `url: 'json.asp'` as a test, including the full URL will require a `Access-Control-Allow-Origin` to be set in the response. – user692942 Mar 05 '15 at 09:43
  • Dot net learner and @Lankymart : tks a lot! Problem solved thanks to you guys!!! All the best! – DANIEL Mar 06 '15 at 20:09
  • @DANIEL Mark as Answer if it is solved your Problem so in future if someone has same problem then they can refer that answer or Give answer which solves your Problem – Nikunj Ratanpara Mar 07 '15 at 05:25
  • Hi @Dotnetlearner, yes, I know.. It's my first question here and I dont know where is the accept button..kkk :D – DANIEL Mar 10 '15 at 16:29
0

Tks @Dot-net-learner and @Lankymart!!!!!!

Thanks to you guys I was finally able to solve - and especially - to understand the problem.

Yes, I was testing the client script only on my computer (with the ASP code at web domain) and then, testing through the jsFiddle too. Of course , in both cases with the CORS issue.

Putting the client script on the same domain - with the ASP code, worked perfectly !

But I Had the CORS issue - to solve this I rewrite the script - and the Classic ASP code to this:

Client-Script:

$.ajax({
    url:'http://www.onecert.com.br/json.asp',
    dataType: 'jsonp',
    jsonp: 'callback',
    error: function(jqXHR, textStatus, errorThrown){
        alert("NO")
    },
    success: function(data){
        alert("YEAAAAAAH!")
    }    });

Server Classic Asp:

   dim callback
   callback = Request("callback")
   Response.Write(callback & "([{""name"": ""Daniel"", ""surname"": ""Smith"", ""message"": ""Hi""}])")

Now, the client-script works out of the ASP Domain including on jsFiddle:

jsFiddle

Tks a lot! people like you guys, who share knowledge, make our "ITworld" better :D :D :D :D

DANIEL
  • 515
  • 7
  • 20