2017-07-27 112 views
0

我正在一个web应用程序,当我尝试使用GET方法来拨打电话,尽管网址和重点是正确的,我总是失败JavaScript的GET方法

的html代码:

<!DOCTYPE html> 
<html> 
<head> 
    <title>cerca</title> 

    <link rel="stylesheet" href="css/main.css"> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
    <script src="js/main.js"></script> 
</head> 
<br> 
<p><img src="img/Bip.png" height="150" width="150"/> 
    Bip business integration partners 
</p> 


<h1>Cerca</h1> 

<form onsubmit="foundTopic()"> 

<input name="mioTesto" type="text" id="topicID" placeholder ="Cerca per topic " size="40" maxlength="200" /> 
<button type="submit" >Cerca</button> 

</form><br></br> 



<form onsubmit="foundActivities()"> 

<input name="mioTesto" type="text" id="activitiesID" placeholder="Cerca per activities" size="40" maxlength="200" /> 
<button type="submit">Cerca</button> 


</form><br> 

<h5><a href="index.html">home</h5> 

</body> 
</html> 

JS代码

function foundTopic() { 

    var topic = document.getElementById("topicID").value; 
    var url2 = "http://localhost:8080/bip/workTagsTopic/" + encodeURI(topic) 
    $.ajax({ 
     type: "GET", 
     url: "http://localhost:8080/bip/workTagsTopic/" + encodeURI(topic), 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: function (data, status, jqXHR) { 
      // do something 
      console.log("okS") 
     }, 
     error: function (jqXHR, status) { 
      console.log(url2) 
      console.log(topic) 

     } 
    }); 
} 

在控制台它打印这样的: http://localhost:8080/bip/workTagsTopic/key2 main.js:17个 KEY2 main.js:18

+0

是网址正在击中? –

+0

是空着,如果我点击书面链接它打开页面与列表 –

+0

它是与$ .get – Amit

回答

0

如果您的js代码正如上面提到的那样写完,那么您应该在几行之后加上分号。

var url2 = "http://localhost:8080/bip/workTagsTopic/" + encodeURI(topic); 

以及写入所有console.log()行的位置。再次检查你的路径。除了这些,你的代码似乎没问题。尝试一下。

+0

它是相同,它不起作用 –

0

不知道非常多,试试这个

function foundTopic(e) { 
    e.preventDefault(); 

    // blablabla 
} 

只是阻止默认submit事件。