AJAX request with different domain

1

My Request

url="http://algumip:algumaporta/dowPDFNF?cChave="+chave

 $.ajax({
    url: url,
    dataType: 'jsonp',
    success: function (data) {
        console.log(JSON.stringify(data));
    },
    type: 'POST'
});

error that returns:

Uncaught SyntaxError: Unexpected token :

However,whenIpasstheurl(generatedbytheurlvariable)directlyintothenavager,Igettherightreturn.Seepicturethereturn:

WhatIneedistogetthisreturntogetthepdfdownload

{"pdf":"http:\\algumip\download\6a423e04e2c2dfd4a59f0001ec8bbf44b9a6a6d-nfe.pdf"}
    
asked by anonymous 10.05.2018 / 16:03

1 answer

2

Try to add the async: false item, because according to the documentation, jsonp requests to remote servers do not work if asynchronous mode is active.

  

Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation.

$.ajax({ 
    async: false, 
    method: 'GET', 
    url: url, 
    contentType: "application/json", 
    jsonpCallback: minhafuncaocallback, 
    dataType: 'jsonp', 
    success: function (json) { 
        console.log(json); 
    }, 
    error: function (jqXHR, textStatus, errorThrown) { 
        console.log("AJAX ERRO" + jqXHR + textStatus + errorThrown); 
    } 
});

This request should be made after the page has been fully loaded because a synchronous request prevents the page load from continuing until the response is received from that request, which can decrease the quality of the page. user experience on your site, if any.

    
11.05.2018 / 00:01