Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

309
Views
No se puede enviar una solicitud entre dominios en la extensión `Firefox`

Estoy tratando de acceder a datos de cross-domain cruzados usando jsonp o XMLHttpRequest con el método GET . Mi código:

XMLHttpSolicitud

 var xhr = new XMLHttpRequest(); xhr.open("GET", "http://example.com/ajax.php?code=BSE", true); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { alert(xhr.responseText); } xhr.send();

JsonP

 $.ajax({ type: 'GET', url: "http://example.com/ajax.php?code=BSE", dataType: "jsonp", jsonpCallback: "jsonp_callback", crossDomain: true, success: function(res){ console.log(res); } });

Ambos métodos tienen el mismo comportamiento. Cada vez que envío una solicitud, simplemente sigue cargando (incluso si no estoy seguro de si está enviando una solicitud o no) y no hace nada.

Y mi código php:

Código PHP:

 header('content-type: application/json; charset=utf-8'); $dts=array('value'=>'123'); echo $_GET['jsonp_callback'] . '('.json_encode($dts).')';
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

XMLHttpRequest funcionará bien, sin necesidad de jsonp. En su manifest.json , asegúrese de solicitar permisos para el dominio en el que está publicando: Chrome no requiere permisos para XHR, pero Firefox sí. Este error se manifiesta en Firefox como un código http 404 en el XHR, pero no hay actividad en el panel de red. Si obtiene un código http 0, también tiene CORS o problemas de seguridad de contenido mixto.

 { "manifest_version": 2, "name": "web extension", "version": "1", "permissions": [ "http://example.com/" ], "content_scripts": [ { // ... } ] }
about 4 years ago · Santiago Trujillo Report

0

Intente usar new XDomainRequest() en su solicitud xhr. XDomainRequest es una implementación de control de acceso HTTP (CORS).

 var createCORSRequest = function(method, url) { var xhr = new XMLHttpRequest(); if ("withCredentials" in xhr) { // Most browsers. xhr.open(method, url, true); } else if (typeof XDomainRequest != "undefined") { // IE8 & IE9 xhr = new XDomainRequest(); xhr.open(method, url); } else { // CORS not supported. xhr = null; } return xhr; }; var url = 'http://example.com/ajax.php?code=BSE'; var method = 'GET'; var xhr = createCORSRequest(method, url); xhr.onload = function() { // Success code goes here. }; xhr.onerror = function() { // Error code goes here. }; xhr.setRequestHeader('content-type', 'application/json; charset=utf-8'); xhr.send();
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!