duanlan7239 2015-06-03 11:50
浏览 85

方法让echo在php脚本中工作,由javascript函数调用$ .POST

Below a javascript/jQuery function that is called when a button with class "postbit_quote" on HTML page on the screen is clicked. The id of the button is stored in the variable post, the variable thread is set to the value of a variable $tid in the php script that created the page, and the variable selected is set to the text which is selected at the moment the button is clicked. Then the $.post method is used to call a php script "newreply.php" with the variables mentioned above passed to the script. This script creates a html document that is echo'ed. Generally this is then shown as a new page that is waiting for a user response. But in this construction the echo'ed information is captured and returned to the javascript through the argument "data" of the .done function. When this variable is written with document.write, the page with the html is shown.

$(document).ready(function(){
    $(".postbit_buttons").on("click",".postbit_quote",function(){
        var post = this.id.substring(5);
        var thread = getUrlParameter("tid");
        selected = window.getSelection().getRangeAt(0).cloneContents();
        $.post("newreply.php",{tid: thread, replyto: post, selection: selected}).done(function(data) {document.write(data)});
    });
});

This works, that's not the problem. The problem is that when the page is shown the url in the address field of the browser is still that of the original script, and not that of the called script (here newreply.php) which is confusing. The second problem is that the indicator that a page is not finished loading (with Firefox a spinning wheel) does not stop until the page is left by some user action.

Is there a way to let the echo in the called script do it's normal job, and control is not returned to javascript?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?