doujia9204 2017-03-04 09:16
浏览 17

piSession.buildPageInteractionSession方法无效

hi I wrote simple AJAX call to php file I am getting error in my console . Request should go to the server and return back in the html input field . i am not able to solve Below is my Code

HTML:

    <label>Input your text: </label><input type="text" id="user_text"   onkeyup="update1()"/></br></br>
    <label>Response here: </label><input type="text" id="server_response"  readonly/>

Javascript:

    function update1(){
var current_text = document.getElementById("user_text").value;
var http = new XMLHttpRequest();
http.onreadystatechange = function(){
    if(http.readyState == 4 && http.status == 200){
        var response = http.responseText;
        document.getElementById('server_response').value = response;
    }
    http.open("GET" , "http://localhost/inderstand_Ajax/server.php?user_text="+current_text , true);
    http.send();
}

};

PHP:

    <?php
    $data = $_GET;
    $user_text = $_GET['user_text'];
    $response = strtoupper($user_text)
    echo $response;
    ?>

Error in the console :

    Uncaught (in promise) Object {message: "Invalid method piSession.buildPageInteractionSession", stack: "Error: Invalid method piSession.buildPageInteracti…on↵    at true-key://data/scripts/core.js:10:8889"}
  • 写回答

3条回答 默认 最新

  • dousheyan0375 2017-03-04 09:19
    关注

    Your code is wrong.

    It should be:

    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
           // Typical action to be performed when the document is ready:
           document.getElementById("server_response").innerHTML = xhttp.responseText;
        }
    };
    xhttp.open("GET", "http://localhost/inderstand_Ajax/server.php?user_text="+current_text, true);
    xhttp.send(); 
    

    and not:

    http.onreadystatechange = function(){
        if(http.readyState == 4 && http.status == 200){
            var response = http.responseText;
            document.getElementById('server_response').value = response;
        }
        http.open("GET" , "http://localhost/inderstand_Ajax/server.php?user_text="+current_text , true);
        http.send();
    }
    

    you cannot send the request inside onreadystatechange.

    评论

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应