找到你要的答案

Q:link not found, 404 error

Q:链接未找到,404错误

I am doing a small school project that is basically a web app that searches nearby restaurants by keywords = restaurant and the specific cuisine that the user chooses. However, I have a problem when getting the website of the place and putting it in "a" tag and when I press the link to test it, it says that the page cannot be found. But the link works perfectly when I copy and paste the link in a new tab in the browser.

This is the jquery that deals with the json output of my request:

var restaurantContactDetails = "https://maps.googleapis.com/maps/api/place/details/json?reference="+restaurant_reference+"&key=API_KEY";
$.getJSON(restaurantContactDetails,function(jsondata){
    $("#restaurant_contact").html("Contacts: " + "<p> UK: " + jsondata.result.formatted_phone_number+ ","+ " International: " + jsondata.result.international_phone_number+"</p>");
    //$("#restaurant_contact").append("<p> International: " + jsondata.result.international_phone_number+"</p>");
    var website = jsondata.result.website;
    //alert(website);
    console.log(website);
    $("#restaurant_website").append("<a href=website >" + website+"</a>");
    for(var i = 0; i < Object.keys(jsondata.result.reviews).length;i++){                
        $("#Client_reviews").append("<p class=rust_reviews>"+"<h4 class=text-success>"+jsondata.result.reviews[i].author_name+"</h4>"+"<pre>"+jsondata.result.reviews[i].text+"</pre>");
    }
});

I should mention that the place website sometimes is a specific link like this: http://www.premierinn.com/en/hotel/ABEPTI/aberdeen-city-centre?cmp=GLBC Any suggestions?

我正在做一个小学校的项目,基本上是一个网络应用程序,搜索附近餐厅的关键字=餐厅和特定的菜,用户选择。然而,我有一个问题时,得到网站的地方,把它在“A”标签,当我按下链接来测试它,它说,该网页无法找到。但是,当我在浏览器中的一个新标签中复制并粘贴链接时,链接就完美地工作了。

这是jQuery,我请求JSON输出处理:

var restaurantContactDetails = "https://maps.googleapis.com/maps/api/place/details/json?reference="+restaurant_reference+"&key=API_KEY";
$.getJSON(restaurantContactDetails,function(jsondata){
    $("#restaurant_contact").html("Contacts: " + "<p> UK: " + jsondata.result.formatted_phone_number+ ","+ " International: " + jsondata.result.international_phone_number+"</p>");
    //$("#restaurant_contact").append("<p> International: " + jsondata.result.international_phone_number+"</p>");
    var website = jsondata.result.website;
    //alert(website);
    console.log(website);
    $("#restaurant_website").append("<a href=website >" + website+"</a>");
    for(var i = 0; i < Object.keys(jsondata.result.reviews).length;i++){                
        $("#Client_reviews").append("<p class=rust_reviews>"+"<h4 class=text-success>"+jsondata.result.reviews[i].author_name+"</h4>"+"<pre>"+jsondata.result.reviews[i].text+"</pre>");
    }
});

I should mention that the place website sometimes is a specific link like this: http://www.premierinn.com/en/hotel/ABEPTI/aberdeen-city-centre?cmp=GLBC Any suggestions?

answer1: 回答1:

Try this:

 $("#restaurant_website").append("<a href=" + website + ">" + website+"</a>");

试试这个:

 $("#restaurant_website").append("<a href=" + website + ">" + website+"</a>");
answer2: 回答2:

Problem in this line

"<a href=website >" + website+"</a>

as website is a variable which contains URL it should be like this

"<a href="+ website + ">" + website+"</a>"

example.

$("#restaurant_website").append("<a href=" + website + ">" + website+"</a>");

这一行的问题

"<a href=website >" + website+"</a>

由于网站是一个包含URL的变量,它应该是这样的

"<a href="+ website + ">" + website+"</a>"

例子.

$("#restaurant_website").append("<a href=" + website + ">" + website+"</a>");
jquery  json  hyperlink  request