weixin_33726313 2017-11-20 10:39 采纳率: 0%
浏览 199

Axios错误404错误

I'm having an issue where I think axios is querying the wrong URL just before query is sent.

getShows : function(){
  if( ! this.query ) return false;
  var getURL = this.makeUrlFromObject(this.query);
  console.log('getURL', getURL);
  var self = this;
  axios.get(getURL).then(function(response){
    console.log('response.data', response.data)
    self.shows = response.data;
  });
},
makeUrlFromObject : function(query){
  var queryArray = [];
  for (var prop in query) {
    if(!query.hasOwnProperty(prop)) continue;
    queryArray.push(prop + "=" + query[prop]);
  }
  var url = this.apiUrl + '?' + queryArray.join('&');
  return url;
},
...

Running the getShows returns the following in the console:

1. getURL /api/all?date=20180131

2. GET http://website.dev/shows/false 404 (Not Found)                     false:1

3. response.data (3) [{…}, {…}, {…}]

I can't seem to diagnose where this false:1 is coming from. The request and response are both working, just this extra request seems to crop up from nowhere.

  • 写回答

1条回答 默认 最新

  • weixin_33743703 2017-12-08 14:14
    关注

    I'm an idiot. Following the ajax request, an image element is created on the page.

    The response (not shown) happened to include an image file that was loaded into 2 of the 3 objects. The 3rd didn't have an image, so it came back as { image : false }.

    When this was then used to create an image template, it was coming back as:

    <div style="background-image:url(false)">
    

    So the console came back with a get request for 'false', which 404d.

    评论

报告相同问题?