1

Hi guys why i have net::ERR_EMPTY_RESPONSE error when i trying to request JSON with jQuery ? as you see if you try url in your browser its work very well but with ajax request have this error please someone tell me how i can fix my problem?

try in your browser:

http://uploads.im/api?upload=http://www.google.com/images/srpr/nav_logo66.png

JS:

url = 'http://www.google.com/images/srpr/nav_logo66.png';
$.ajax({
        type: "POST", 
        cache: false,
        dataType: 'json',
        url: "http://uploads.im/api?upload="+url,
        success: function(a) {
            if ( a.status_code === 200 ){
                c = a.data;

                alert(c.img_url)
                alert(c.thumb_url)

            } else if ( a.status_code ) {
                alert('error');
            } else {
                alert('error2');
            }
        }
    });

jsfiddle:

https://jsfiddle.net/raminr63/bgu00oas/
MrtinDo
  • 23
  • 1
  • 4
  • Refer post - https://stackoverflow.com/questions/37835232/java-with-ajax-err-empty-response-ajax-response-throws-error-while-server-is/37983882#37983882?newreg=374679a32c5f48bc9e7d37db6cd85548 – Nitin Gore Jul 24 '17 at 22:16

2 Answers2

1

Change POST to GET.

type: "GET"

See http://codepen.io/mark_c/pen/mrZOWV

mark_c
  • 1,202
  • 1
  • 8
  • 10
  • Brilliant! So simple, but totally effective (for me). Thank you. Annoyingly, on my localhost WAMP setup, the POST option works fine. – Alan N Jan 13 '18 at 11:56
0

If you're using apache2: Check you've got Headers enabled in httpd.conf LoadModule headers_module libexec/apache2/mod_headers.so

maffn
  • 1