2017-11-21 6 views
0

あるページから別の埋め込みページに結果(POSTの戻り値)を渡したいのですが、どうすればいいのか分かりません。 ej2ファイルを持っている メインのHTMLページ(のwelcome.html)(Buttom.html):投稿結果を1つのHTMLから他のHTMLに渡すには?

のwelcome.html:

<html> 

    <body> 

    <script type = "text/javascript" src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>  
    <script type = "text/javascript"> 
    $(document).ready(function(){   

        $("#submit").click(function(){ 

        xhr.open("POST", "/addGrade", true); 
        xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); 
        data = // logic to get the data (i skipped adding this part) 
        xhr.send(data); 
        xhr.onloadend = function() { 
         // HERE I WANT TO PASS THE RESULTS TO Buttom.html 
        }; 

       }); // click on submit 
     }); // ready 


     </script> 

    <form id="gradeForm"> 
      <p> 
       <label>Name:</label> 
       <input type="text" name="name" id="name"> 
      </p>    
      <p> 
       <label>Grade:</label> 
       <input type="text" name="grade" id="grade" value="100"> 
      </p> 
      <p> 
       <button type="button" id="submit" >submit</button> 
      </p>    
    </form> 

    <div> 
    <%include Buttom.html%> 
    </div> 

    </body> 
</html> 

Buttom.html:

構造は次のようになり

<head> 

</head> 

<body> 


<script type = "text/javascript" src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>   
<script type = "text/javascript"> 

    $(document).ready(function(){   
    }); // ready 
</script> 


<p id="ppp"> 
    <!-- Here I want to add the results --> 
<p> 


</body> 

POST(welcome.html内)からButtom.html(Buttom.html内のjsの機能)にどのように結果を渡すことができますか?

+0

すでにjQueryを使用しているので、これは '$ .ajax'や' $。post'を使ってもっと簡単になり、ドキュメントの例に従います – charlietfl

+0

HTMLはこのように動的ではありません。サーバーテクノロジーを使用するか、クッキーまたは同等のものにJavaScriptを使用してデータを格納する必要がありますが、これに対してお勧めします –

+0

何か不足していますか? headセクションとbodyセクションを含むHTMLファイルをDIV要素サーバー側に含めても、有効なHTMLは生成されません。 – traktor53

答えて

0

のwelcome.html Buttom.html ON

$(document).ready(function(){   

        $("#submit").click(function(){ 

        xhr.open("POST", "/addGrade", true); 
        xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); 
        data = // logic to get the data (i skipped adding this part) 
        xhr.send(data); 
        xhr.onloadend = function() { 
         // If your data is big then use cookies or create form and send it to another page 

        var url = "YourPage?data=" + encodeURIComponent(YOUR_DATA); 
        window.location.href = url; 



        }; 

       }); // click on submit 
     }); // ready 

$(document).ready(function(){ 


var queryString = new Array(); 
    $(function() { 
     if (queryString.length == 0) { 
      if (window.location.search.split('?').length > 1) { 
       var params = window.location.search.split('?')[1].split('&'); 
       for (var i = 0; i < params.length; i++) { 
        var key = params[i].split('=')[0]; 
        var value = decodeURIComponent(params[i].split('=')[1]); 
        queryString[key] = value; 
       } 
      } 
     } 
     if (queryString["name"] != null) { 
      // YOUR CODE 

     } 
    });   

})。

+0

は動作しないようです。私は「取得できません/Buttom.html」 – user3668129

+0

真剣に、Bottom.htmlはあなたのページですので、正確なパスを教えてください。 –

+0

@ user3668129答えが更新されましたので、確認してください。 –

関連する問題