dpz3471 2015-08-10 06:57
浏览 156
已采纳

在jquery AJAX调用中丢失了http://前缀

Can somebody please explain why I lose the 'http://' prefix in the response at '"thumbnail":"127.0.0.1:8888\/selfstudy...'?

[{"makeModelDescription":"Corvette C5 Cabrio","firstRegistration":"EZ 03\/2001","mileage":"96.000 km","thumbnail":"127.0.0.1:8888\/selfstudy\/projects\/ad\/res\/test\/212302246\/00\/s\/NjgxWDEwMjQ=\/z\/KL0AAOSwfcVUEyyr\/$_18.JPG","carDetailsURL":"http:\/\/127.0.0.1:8888\/selfstudy\/projects\/ad\/res\/test\/212302246.php","isInsideMysqlDb":"yes"},{"makeModelDescription":"BMW X5 4.4 i  aus erster Hand","firstRegistration":"EZ 07\/2000","mileage":"226.000 km","thumbnail":"http:\/\/localhost:8888\/selfstudy\/projects\/ad\/res\/test\/212302263\/00\/s\/MTE5NFgxNjAw\/z\/USEAAOSwjVVVgwpL\/$_18.JPG","carDetailsURL":"http:\/\/127.0.0.1:8888\/selfstudy\/projects\/ad\/res\/test\/212302263.json","isInsideMysqlDb":"yes"}]

I generate the JSON in this way:

echo '{
  "SUPPRESS_DEALER_REPORTING_FOR_AD_IDS": [
    212302265,
    212382107,
    212530244,
    212302263,
    212302246
  ],
  "REQUEST_LANGUAGE_SETTINGS": "de",
  "org.springframework.validation.BindingResult.SUPPRESS_DEALER_REPORTING_FOR_AD_IDS": {
    "target": [
      212302265,
      212382107,
      212530244,
      212302263,
      212302246
    ],
    "autoGrowNestedPaths": true,
    "autoGrowCollectionLimit": 256,
    "objectName": "SUPPRESS_DEALER_REPORTING_FOR_AD_IDS",
    "messageCodesResolver": {
      "prefix": "",
      "formatter": "PREFIX_ERROR_CODE"
    },
    "errors": [],
    "suppressedFields": [],
    "nestedPath": "",
    "nestedPathStack": []
  },
  "org.springframework.validation.BindingResult.REQUEST_LANGUAGE_SETTINGS": {
    "target": "de",
    "autoGrowNestedPaths": true,
    "autoGrowCollectionLimit": 256,
    "objectName": "REQUEST_LANGUAGE_SETTINGS",
    "messageCodesResolver": {
      "prefix": "",
      "formatter": "PREFIX_ERROR_CODE"
    },
    "errors": [],
    "suppressedFields": [],
    "nestedPath": "",
    "nestedPathStack": []
  },
  "page": {
    "ad": {
      "makeName": {"value": "Corvette"},
      "modelName": {"value": "C5"},
      "damagedVehicle": {"value": ""},
      "exportVehicle": {},
      "countryVersion": {},
      "images": [
        {
          "thumbnail": {"src": "' . ($_SERVER['REMOTE_ADDR'] == '::1' ? 'http://127.0.0.1' : $_SERVER['REMOTE_ADDR']).':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['PHP_SELF']).'/212302246/00/s/NjgxWDEwMjQ=/z/KL0AAOSwfcVUEyyr/$_18.JPG"},
          "medium": {"src": "' . ($_SERVER['REMOTE_ADDR'] == '::1' ? 'http://127.0.0.1' : $_SERVER['REMOTE_ADDR']).':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['PHP_SELF']).'/212302246/00/s/NjgxWDEwMjQ=/z/KL0AAOSwfcVUEyyr/$_24.JPG"},
          "large": {"src": "' . ($_SERVER['REMOTE_ADDR'] == '::1' ? 'http://127.0.0.1' : $_SERVER['REMOTE_ADDR']).':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['PHP_SELF']).'/212302246/00/s/NjgxWDEwMjQ=/z/KL0AAOSwfcVUEyyr/$_27.JPG"}
        },
        {
          "thumbnail": {"src": "' . ($_SERVER['REMOTE_ADDR'] == '::1' ? 'http://127.0.0.1' : $_SERVER['REMOTE_ADDR']).':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['PHP_SELF']).'/212302246/00/s/NjgxWDEwMjQ=/z/LigAAOSwfcVUEyzY/$_18.JPG"},
          "medium": {"src": "' . ($_SERVER['REMOTE_ADDR'] == '::1' ? 'http://127.0.0.1' : $_SERVER['REMOTE_ADDR']).':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['PHP_SELF']).'/212302246/00/s/NjgxWDEwMjQ=/z/LigAAOSwfcVUEyzY/$_24.JPG"},
          "large": {"src": "' . ($_SERVER['REMOTE_ADDR'] == '::1' ? 'http://127.0.0.1' : $_SERVER['REMOTE_ADDR']).':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['PHP_SELF']).'/212302246/00/s/NjgxWDEwMjQ=/z/LigAAOSwfcVUEyzY/$_27.JPG"}
        },
        {
          "thumbnail": {"src": "' . ($_SERVER['REMOTE_ADDR'] == '::1' ? 'http://127.0.0.1' : $_SERVER['REMOTE_ADDR']).':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['PHP_SELF']).'/212302246/00/s/NjgxWDEwMjQ=/z/FukAAOSwnDZUEyzH/$_18.JPG"},
          "medium": {"src": "' . ($_SERVER['REMOTE_ADDR'] == '::1' ? 'http://127.0.0.1' : $_SERVER['REMOTE_ADDR']).':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['PHP_SELF']).'/212302246/00/s/NjgxWDEwMjQ=/z/FukAAOSwnDZUEyzH/$_24.JPG"},
          "large": {"src": "' . ($_SERVER['REMOTE_ADDR'] == '::1' ? 'http://127.0.0.1' : $_SERVER['REMOTE_ADDR']).':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['PHP_SELF']).'/212302246/00/s/NjgxWDEwMjQ=/z/FukAAOSwnDZUEyzH/$_27.JPG"}
        },
        {
          "thumbnail": {"src": "' . ($_SERVER['REMOTE_ADDR'] == '::1' ? 'http://127.0.0.1' : $_SERVER['REMOTE_ADDR']).':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['PHP_SELF']).'/212302246/00/s/NjgxWDEwMjQ=/z/lUYAAOSwRLZUEyy6/$_18.JPG"},
          "medium": {"src": "' . ($_SERVER['REMOTE_ADDR'] == '::1' ? 'http://127.0.0.1' : $_SERVER['REMOTE_ADDR']).':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['PHP_SELF']).'/212302246/00/s/NjgxWDEwMjQ=/z/lUYAAOSwRLZUEyy6/$_24.JPG"},
          "large": {"src": "' . ($_SERVER['REMOTE_ADDR'] == '::1' ? 'http://127.0.0.1' : $_SERVER['REMOTE_ADDR']).':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['PHP_SELF']).'/212302246/00/s/NjgxWDEwMjQ=/z/lUYAAOSwRLZUEyy6/$_27.JPG"}
        },
        {
          "thumbnail": {"src": "' . ($_SERVER['REMOTE_ADDR'] == '::1' ? 'http://127.0.0.1' : $_SERVER['REMOTE_ADDR']).':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['PHP_SELF']).'/212302246/00/s/NjgxWDEwMjQ=/z/GJoAAOSwnDZUEyzl/$_18.JPG"},
          "medium": {"src": "' . ($_SERVER['REMOTE_ADDR'] == '::1' ? 'http://127.0.0.1' : $_SERVER['REMOTE_ADDR']).':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['PHP_SELF']).'/212302246/00/s/NjgxWDEwMjQ=/z/GJoAAOSwnDZUEyzl/$_24.JPG"},
          "large": {"src": "' . ($_SERVER['REMOTE_ADDR'] == '::1' ? 'http://127.0.0.1' : $_SERVER['REMOTE_ADDR']).':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['PHP_SELF']).'/212302246/00/s/NjgxWDEwMjQ=/z/GJoAAOSwnDZUEyzl/$_27.JPG"}
        }
      ],
      "internalNumber": {"link": {}},
      "additionalAttributes": [
        {
          "label": "Hubraum",
          "link": {},
          "value": "5666 cm³"
        },
        {
          "label": "Anzahl Sitzplätze",
          "link": {},
          "value": "2"
        },
        {
          "label": "Anzahl der Türen",
          "link": {},
          "value": "2/3"
        },
        {
          "label": "Schadstoffklasse",
          "link": {},
          "value": "Euro3"
        },
        {
          "label": "Umweltplakette",
          "link": {},
          "value": "4 (Grün)"
        },
        {
          "label": "HU/AU",
          "link": {},
          "value": "Neu"
        },
        {
          "label": "Farbe",
          "link": {},
          "value": "Schwarz (Metallic)"
        },
        {
          "label": "Innenausstattung",
          "link": {},
          "value": "Vollleder"
        }
      ],
      "genericFeatures": {
        "headline": {},
        "features": [],
        "available": false
      },
      "interiorFeatures": {
        "headline": {"value": "Innenausstattung"},
        "features": [
          {
            "value": "Bordcomputer",
            "enabled": true
          },
          {
            "value": "CD-Spieler",
            "enabled": true
          },
          {
            "value": "Elektr. Fensterheber",
            "enabled": true
          },
          {
            "value": "Elektr. Sitzeinstellung",
            "enabled": true
          },
          {
            "value": "Head-Up Display",
            "enabled": true
          },
          {
            "value": "Klimatisierung (Klimaautomatik)",
            "enabled": true
          },
          {
            "value": "Servolenkung",
            "enabled": true
          },
          {
            "value": "Sitzheizung",
            "enabled": true
          },
          {
            "value": "Sportsitze",
            "enabled": true
          },
          {
            "value": "Tempomat",
            "enabled": true
          },
          {
            "value": "Tuner/Radio",
            "enabled": true
          },
          {
            "value": "Zentralverriegelung",
            "enabled": true
          }
        ],
        "available": true
      },
      "exteriorFeatures": {
        "headline": {"value": "Außenausstattung"},
        "features": [
          {
            "value": "Elektr. Seitenspiegel",
            "enabled": true
          },
          {
            "value": "Leichtmetallfelgen",
            "enabled": true
          },
          {
            "value": "Sportfahrwerk",
            "enabled": true
          },
          {
            "value": "Sportpaket",
            "enabled": true
          }
        ],
        "available": true
      },
      "extrasFeatures": {
        "headline": {"value": "Extras"},
        "features": [
          {
            "value": "Scheckheftgepflegt",
            "enabled": true
          }
        ],
        "available": true
      },
      "securityFeatures": {
        "headline": {"value": "Sicherheit & Umwelt"},
        "features": [
          {
            "value": "ABS",
            "enabled": true
          },
          {
            "value": "Airbags (Front-, Seiten- und weitere Airbags)",
            "enabled": true
          },
          {
            "value": "Elektr. Wegfahrsperre",
            "enabled": true
          },
          {
            "value": "Nebelscheinwerfer",
            "enabled": true
          }
        ],
        "available": true
      },
      "galleryFeatures": [
        {"value": "Klimatisierung (Klimaautomatik)"},
        {"value": "Sitzheizung"},
        {"value": "Tempomat"},
        {"value": "Servolenkung"},
        {"value": "Elektr. Fensterheber"},
        {"value": "Zentralverriegelung"},
        {"value": "Bordcomputer"},
        {"value": "CD-Spieler"},
        {"value": "Elektr. Sitzeinstellung"},
        {"value": "Head-Up Display"},
        {"value": "Tuner/Radio"},
        {"value": "Sportsitze"},
        {"value": "Leichtmetallfelgen"},
        {"value": "Elektr. Seitenspiegel"},
        {"value": "Sportfahrwerk"},
        {"value": "Sportpaket"},
        {"value": "Scheckheftgepflegt"},
        {"value": "Airbags (Front-, Seiten- und weitere Airbags)"},
        {"value": "ABS"},
        {"value": "Elektr. Wegfahrsperre"}
      ],
      "description": {"value": "Head - Up Display, Klimaautomatik, Elektr. Fensterheber, Elektr. Seitenspiegel, Elektr. Sitze, Bordcomputer, Sportfahrwerk, Sportpaket, Sportsitze, Vollleder mit Alcantara.<br><br>Hinten: 285/35 ZR 19<br>Vorne: 245/35 R19<br><br>Motor ist offen keine Abrigelung ab 250 km/h<br>Sehr sauber gehalten in einem sehr gutem zustand. Garagefahrzeug und Nichtraucherfahrzeug. Reifen vorne wurden erneuert. Ein Corvette f&uuml;r liebhaber.&nbsp;<br>In dem Corvette wurde ein neues Getriebe eingebaut. Alle Rechnungen liegen vor.&nbsp;<br><hr>Finanzierung m&ouml;glich!<br><br>&Auml;nderungen,Irrt&uuml;mer und Zwischenverkauf vorbehalten!"},
      "slideshowJson": "https://home.mobile.de/home/slideshow.json",
      "slideshowAvailable": false,
      "callAnalystPhoneNumbers": [],
      "adId": 212302246,
      "priceModel": {
        "type": {},
        "secondaryPrice": {
          "countryOfSale": {},
          "countryOfOrigin": {},
          "net": true
        },
        "primaryPrice": {
          "countryOfSale": {"value": "25.999 EUR"},
          "countryOfOrigin": {},
          "net": false
        },
        "previousPrice": {},
        "deliveryCost": {},
        "vatRate": {"value": "MwSt. nicht ausweisbar"},
        "infoText": {},
        "vatReclaimable": false
      },
      "makeModelDescription": {"value": "Corvette C5 Cabrio"},
      "bodyType": {"value": "Cabrio/Roadster"},
      "usageType": {"value": "Gebrauchtfahrzeug"},
      "firstRegistration": {"value": "EZ 03/2001"},
      "mileage": {"value": "96.000 km"},
      "fuelConsumption": [
        {
          "label": "Kraftstoffverbr. komb.",
          "link": {},
          "infoIcon": "Bei den angegebenen Daten handelt es sich um Circa-Angaben des Angebot-Erstellers. Die Werte können Erfahrungen zu diesem Modell darstellen oder aus anderen Quellen stammen.",
          "value": "ca. 12,1 l/100 km"
        },
        {
          "label": "Kraftstoffverbr. innerorts",
          "link": {},
          "value": "ca. 17,4 l/100 km"
        },
        {
          "label": "Kraftstoffverbr. außerorts",
          "link": {},
          "value": "ca. 9,1 l/100 km"
        },
        {
          "label": "CO²-Emissionen komb.",
          "link": {},
          "value": "ca. 290 g/km"
        },
        {
          "label": "Zugr.-lgd. Treibstoffart",
          "link": {},
          "infoIcon": "Die Ermittlung der Verbrauchs- und Emissionswerte sowie die Energieeffizienzklasse basieren auf der Verwendung dieser Treibstoff-Art.",
          "value": "Benzin"
        }
      ],
      "attributes": [
        {"value": "EZ 03/2001"},
        {"value": "96.000 km"},
        {"value": "Benzin"},
        {"value": "253 kW (344 PS)"},
        {"value": "Automatik"}
      ],
      "videoLinkPresent": false,
      "advice": {},
      "secret": "8374ce3e8787ca5fe844b8df26fd2583",
      "availability": {}
    },
    "recommendVehicle": {
      "url": "mailto:?subject=ich habe ein interessantes Fahrzeug bei mobile.de gefunden: &amp;body=Hallo, %0D%0Aich habe ein interessantes Fahrzeug bei mobile.de gefunden: %0D%0A%0D%0ACorvette%20C5%20Cabrio%0D%0A%0D%0Ahttp://suchen.mobile.de/fahrzeuge//details.html?id=212302246",
      "alt": "Fahrzeug weiterempfehlen"
    }
  }
}';

And when I open the php file with the JSON string in the browser I can see that the thumbnail URL is correct "thumbnail": {"src": "http://127.0.0.1:8888/selfstudy/projects/ad/res/test/212302246/00/s/NjgxWDEwMjQ=/z/KL0AAOSwfcVUEyyr/$_18.JPG"}

But when I do a jquery AJAX request

$.ajax({
            url: 'getCarOverview.php',
            type: 'GET',
            dataType: 'json',
            async: true,
            cache: false,
            data: {'env':environment},
            success: function (response) {
                $('#table__cars').remove();
                $('<table></table>')
                    .addClass('table table-bordered table-striped margin__bottom__10')
                    .attr('id', 'table__cars')
                    .appendTo('#row--e6s4d');

                $.each(response, function(key, value) {
                    $('#table__cars').append('<tbody data-set='+key+' data-url='+value.carDetailsURL+'></tbody>');
                    $('tbody[data-set='+key+']')
                        .append('<tr><td rowspan=3><img class="img--thumbnail" src="'+value.thumbnail+'"></td><td>Model</td><td>'+value.makeModelDescription+'</td><td rowspan=2><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></td></tr>')
                        .append('<tr><td>Erstzulassung</td><td>'+value.firstRegistration+'</td></tr>')
                        .append('<tr><td>Killometerstand</td><td>'+value.mileage+'</td><td>'+value.isInsideMysqlDb+'</td></tr>');
                });

                $('#btn__insertCars').remove();
                $('#table__cars').after('<div><button type="button" class="btn btn-default btn-block" id="btn__insertCars">Insert cars into database</button></div>');
                $('body').animate({
                    scrollTop: $('#btn__insertCars').offset().top
                }, 1000);
            },
            error: function (xhr, status, error) {
                $('<div><strong>' + status + ' </strong>: ' + error + 'URL' + '<br/><strong> Request URL: </strong>' + this.url + '</div>')
                    .addClass('alert alert-danger')
                    .attr('id', 'error-message-box')
                    .appendTo('#headline');
            }
        });

I get as response the thumbnail URL without http:// as commented at the beginning. Why is this happening?

  • 写回答

1条回答 默认 最新

  • dongpeixiong5943 2015-08-10 07:17
    关注

    Basically what is happening is that the http:// is only appearing in the event that you are resolving your host via ipv6.

    "thumbnail": {"src": "' . ($_SERVER['REMOTE_ADDR'] == '::1' ? 'http://127.0.0.1' : $_SERVER['REMOTE_ADDR']).':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['PHP_SELF']).'/212302246/00/s/NjgxWDEwMjQ=/z/KL0AAOSwfcVUEyyr/$_18.JPG"},
    

    Should become

    "thumbnail": {"src": "http://' . ($_SERVER['REMOTE_ADDR'] == '::1' ? '127.0.0.1' : $_SERVER['REMOTE_ADDR']).':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['PHP_SELF']).'/212302246/00/s/NjgxWDEwMjQ=/z/KL0AAOSwfcVUEyyr/$_18.JPG"},
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?