Execute php url from jscript
Execute php url from jscript
所以我有这个确实工作。基本上,我想执行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
相关文章:
- JavaScript错误:Microsoft JScript运行时错误:应为对象
- Sharepoint JScript if语句未执行
- Validate JSON from Mongo?
- 调用C++中JScript中的instanceof运算符(IDispatch/IDispatchEx)
- Get JSON from an url
- creating objects from variables ES6
- getting id from jsp
- jquery使用name from变量按类选择元素
- Using jQuery with classes from ES6
- 试图在Windows上执行package.json中的脚本会引发JScript错误
- 如何计算与php中的CRC32函数兼容的arrayBuffer(javascript中的From FileReader)
- 带有Request.Form的JScript数组
- 如何删除'被按压'state from复选框
- 当我的所有 Ng-from 都有效时启用一个按钮
- JScript 错误: 无法分配给函数结果
- 在JScript 5.8/WSH中具有属性查找的函数名
- Microsoft JScript运行时错误:无法获取属性'的值;样式':对象为null或未定义
- getDocument by id/get input text from button dons'不起作用
- Xpath from JScript
- Execute php url from jscript