简体   繁体   中英

Jquery ajax get xml parse error

I want get a XML from this url usin Jquery ajax https://sisa.msal.gov.ar/sisa/services/rest/puco/44003375

Via browser I can see this:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<puco>
 <resultado>OK</resultado>
 <coberturaSocial>O.S.P. CIUDAD AUT</coberturaSocial>
<denominacion>AGOSTINO RODRIGO LEONARDO</denominacion>
<nrodoc>44003375</nrodoc>
<rnos>901001</rnos>
<tipodoc>DNI</tipodoc>
</puco>

But when doing:

var id=44003375;
$.ajax({
    type : "GET",
    url  : 'https://sisa.msal.gov.ar/sisa/services/rest/puco/'+id,
    dataType :"JSONP",
    jsonp: true,
    success : function(xhr){
      alert(JSON.stringify(xhr));
    },
    error : function(httpReq,status,exception){
      var clientid = $(httpReq).text();
      alert(JSON.stringify(httpReq));
    }
 });

Return "Parse error"... how I can get via ajax what the browser shows?

使用JavaScript .load() ,然后将XML解析为JSON ,如此处所述

You will need to use any xml to json converter or parser. Have a look at http://goessner.net/download/prj/jsonxml/

I resolved, but with PHP

<?php 
  $response = file_get_contents('https://sisa.msal.gov.ar/sisa/services/rest/puco/44003375');
  $response = new SimpleXMLElement($response);
  dd($response);
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM