jquery ajax get responsetext from http url

后端 未结 9 1331
盖世英雄少女心
盖世英雄少女心 2020-12-07 19:14

Neither:

var response = $.ajax({
    type: \"GET\",   
    url: \"http://www.google.de\",   
    async: false,
    success : function() {
        alert (this         


        
9条回答
  •  暖寄归人
    2020-12-07 20:02

    in jquery ajax functions, the success callback signature is:

    function (data, textStatus) {
      // data could be xmlDoc, jsonObj, html, text, etc...
      this; // the options for this ajax request
    }
    

    depending on the data type you've asked, using the 'dataType' parameter, you'll get the 'data' argument.

    from the docs:

    dataType (String) Default: Intelligent Guess (xml or html). The type of data that you're expecting back from the server. If none is specified, jQuery will intelligently pass either responseXML or responseText to your success callback, based on the MIME type of the response.

    The available types (and the result passed as the first argument to your success callback) are:

    "xml": Returns a XML document that can be processed via jQuery.

    "html": Returns HTML as plain text; included script tags are evaluated when inserted in the DOM.

    "script": Evaluates the response as JavaScript and returns it as plain text. Disables caching unless option "cache" is used. Note: This will turn POSTs into GETs for remote-domain requests.

    "json": Evaluates the response as JSON and returns a JavaScript Object.

    "jsonp": Loads in a JSON block using JSONP. Will add an extra "?callback=?" to the end of your URL to specify the callback. (Added in jQuery 1.2)

    "text": A plain text string.

    see http://docs.jquery.com/Ajax/jQuery.ajax#options

提交回复
热议问题