2017-07-27 5 views
0

私はWebアプリケーションを作っていると私は、GETメソッドを使用して電話をかけるしようとすると、URLとキーは右であるにもかかわらず、私はいつも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を http://localhost:8080/bip/workTagsTopic/key2 main.js:17 KEY2のmain.js:18

0コンソールでコード

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) 

     } 
    }); 
} 

は、この印刷します

+0

URLがヒットしていますか? –

+0

ありがとうございました。書いたリンクをクリックすると、リスト付きのページが開きます –

+0

$ .get – Amit

答えて

0

上記のようにjsコードが正確に書かれていれば、数行後にセミコロンを置く必要があります。

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

また、すべてのconsole.log()行が記述されています。また、パスを再度確認してください。これらのほかに、あなたのコードは大丈夫です。それを試してみてください。

+0

同じ、それは動作しません –

0

非常にわからない、単にデフォルトsubmitイベントを防ぐため、この

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

    // blablabla 
} 

を試してみてください。