Execute php url from jscript

Execute php url from jscript

本文关键字:jscript from url php Execute      更新时间:2023-09-26

所以我有这个确实工作。基本上,我想执行sendTo php文件而不更改到新页面。这个位置会导致我的页面转到php,我不想这样。我可以从php页面将其重定向到原始页面,但我不喜欢这样做。这只是一些代码添加到一个旧的应用程序,它不需要漂亮,它需要工作。

function showVal(newVal, taskid){
    var sendTo = "update_event.php?id_task=" + taskid + "&done=" + newVal;
    document.location.href = sendTo;
}

你可以使用jQuery,你需要做的是执行一个ajax请求。

首先在你的页面中加入jQuery:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

然后在你的javascript中你可以这样做:

function showVal(newVal, taskid) {
   $.get('update_event.php', { id_task: taskid, done: newVal}, 
       function(returnedData){
            console.log(returnedData);
   });
}

好的,因为你需要一个快速修复,我认为导入jquery不会是一个完整的交易,这将是一个使用ajax的例子…

   function showVal(newVal, taskid){
    $.ajax({url: "update_event.php?id_task=" + taskid + "&done=" + newVal;, success: function(result){
        //here you can do things with the return result, for example, if you want to display it inside a div
            $("#div1").html(result);
        //or if you just want to alert it 
            alert(result);
        // if you dont want to do anithing, just leave the result in blank.
    }});

如果你不想下载jquery,你可以直接链接到

   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

希望能有所帮助。

从web开发的黑暗时代快速和肮脏,只需隐藏一个空白的iFrame在页面的某个地方,像这样:

function showVal(newVal, taskid){
    var sendTo = "update_event.php?id_task=" + taskid + "&done=" + newVal;
    document.getElementById('yourhiddenframe').src = sendTo;
}

如果你需要检查执行,查看onLoad iFrame