Ajax - Cross domain get request with jQuery using jsonp

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I m having trouble getting a cross domain request to work with jQuery and can t seem to figure out what s going on. Basically I m trying to query a Solr server and neither the success or error functions are being called. When in the Javascript console for Chrome I do not get any sort of error. Also, when I only type in "mysolrserver/?wt=json&q=title:uw" into the url bar I get a json formatted string.

I replaced my ip with "mysolrserver". Thank you in advance!

My javascript file:

"use strict";
(function() {
    window.onload = function(){
        document.getElementById("search").onclick = request;
    }

    function request(){
        $.ajax( mysolrserver/?wt=json&q=title:uw , {
          dataType:  jsonp ,
          success: function(data){
            alert("Success");
          },
          error: function(error, data, type){
            alert(data + ": " + type + "."); //type isn t giving any response.
          }
        });
    }
})();
  Update:   

In the json response I get from the server, the beginning section is this (I ommited the response section because it s return a ton of text): {"responseHeader":{"status":0,"QTime":2,"params":{"q":"title:uw","callback":"jQ‌​uery1102035263595171272755_1383771206800","_":"1383771206801","wt":"json"}},"resp‌​onse":

So I assume you re meaning this: "callback":"jQuery1102035263595171272755_1383771206800"

Answers

http://api.jquery.com/jquery.ajax/ http://api.jquery.com/jquery.ajax/

    $.ajax( mysolrserver/?wt=json&q=title:uw , {
      jsonp:  json.wrf ,
      dataType:  jsonp ,
      success: function(data){
        alert("Success");
      },
      error: function(error, data, type){
        alert(data + ": " + type + "."); //type isn t giving any response.
      }
    });

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/19944082/cross-domain-get-request-with-jquery-using-jsonp

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils