如何在没有onclick / onkeyup / onchange的情况下调用Ajax函数等(How to call Ajax functions without onclick/onkeyup/onchange etc)
我试图包含一个.php文件,它将通过从MySQL数据库中提取问题来为我生成一个表单。 我找到了很多方法来调用这个函数,我用一个参数(页码)调用了getQuestions()。 我见过使用onchange或按钮(onclick)等执行我的php文件的下拉菜单,但有没有办法使用我的功能没有这些? 我只是希望它可以自动加载页面的其余部分,而不会有任何不必要的交互。
不知道这是否重要,但我的页面是在jQuery Mobile中创建的,所以只有在正确的页面/ div-id处于活动状态时才能看到。
function getQuestions(str) { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("page_1").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","generate_questions.php?p="+str,true); xmlhttp.send(); }
这些是我试图用来在HTML的其余部分查看.php的函数(没有成功)
<script type="text/javascript"> $(document).ready(function() { getQuestions(1); }); </script> window.onload = function() { $("#page_1").load(getQuestions(1)); } window.onload = function() { getQuestions(1); }
I am trying to include a .php file that will generate a form for me by picking out questions from a MySQL database. I've found numerous ways to call this function that I have called getQuestions() with 1 parameter (page number). I've seen drop down menus that will execute my php file using onchange, or buttons (onclick) etc. But is there a way to use my function without these? I just want it to automatically load with the rest of the page without any unnecessary interactions.
Don't know if this matters but my page is made in jQuery Mobile so it should only be visible when the correct page/div-id is active.
function getQuestions(str) { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("page_1").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","generate_questions.php?p="+str,true); xmlhttp.send(); }
These are the functions I have tried to use to view the .php within the rest of the HTML (without success)
<script type="text/javascript"> $(document).ready(function() { getQuestions(1); }); </script> window.onload = function() { $("#page_1").load(getQuestions(1)); } window.onload = function() { getQuestions(1); }
原文:https://stackoverflow.com/questions/11310923
最满意答案
创建新记录时,默认的int id值为0。
这个想法是当您点击保存按钮时,记录被发送到服务器,您需要返回具有更新ID的项目(从数据库中检索到的项目)。 然后当网格读取该值并且看到它与默认值(零)不同时,它将返回客户端,它将新记录标记为已成功插入。 如果没有返回任何项目或缺少更新的id值,Grid将继续将记录标记为脏,并且在将来的save / saveChanges按钮单击时它将继续将其重新发送到服务器。
如果要更改默认ID值,可以在模型定义中使用DefaultValue方法。
.Model(model => model.Id(p => p.Id).DefaultValue(-42))
Problem Solved! I was using older version of KendoUI and it didn't have requestEnd so I started using AddModelError to handle server side results. Actually I used AddModelError not for error but just telling the client side that adding/editing the item was with success.
It was actually a very bad idea but I didn't have a choice at moment. In the client side I was raising Events.Error("result_handler"). Kendo though that it really is an error so it didn't made any changes on the ui but setting the dirty property to true!
Now my boss is trying to get new version of KendoUI in the meanwile I'm using ajaxComplete to raise other events. Unfortunately I don't really have much of a choice until I get the newer version!
相关问答
更多-
这一行: outterGridDataSource.data = dataForGrid.Data.Data; 应该是 outterGridDataSource.data(dataForGrid.Data.Data); (你的问题中缺少很多代码,所以这主要是猜测) The problem was actually: outterGrid.dataSource.transport.read needed to be over-written. The plugin we were building on ...
-
使用标准的双击事件。 第一次点击将选择网格行,添加一个.k-state-selected类,第二次点击将触发双击事件。 $("#yourgridname").on("dblclick", "tr.k-state-selected", function () { // insert code here }); Use the standard double click event. The first click will select the grid row, adding a .k-state ...
-
基本上要更改滚动位置,您将需要使用Grid的dataBound事件。 例如 dataBound:function(){ this.content.scrollTop(this.tbody.height()) }, 以下是网格版本的一个实例 - 同样的方法可以用于包装: http://jsbin.com/aqoqim/3/edit Basically to change the scroll position you will need to use the dataBound even ...
-
创建新记录时,默认的int id值为0。 这个想法是当您点击保存按钮时,记录被发送到服务器,您需要返回具有更新ID的项目(从数据库中检索到的项目)。 然后当网格读取该值并且看到它与默认值(零)不同时,它将返回客户端,它将新记录标记为已成功插入。 如果没有返回任何项目或缺少更新的id值,Grid将继续将记录标记为脏,并且在将来的save / saveChanges按钮单击时它将继续将其重新发送到服务器。 如果要更改默认ID值,可以在模型定义中使用DefaultValue方法。 .Model(model => ...
-
自己解决:对于pdf,allPages =“true”有效。 网格刷新:FOR requestEnd事件 function onRequestEnd(e) { if (e.type == "create") { e.sender.read(); } else if (e.type == "update") { e.sender.read(); } } Resolved myself ...
-
只要您选择了要删除的行,这就是为我工作的内容。 var grid= $("#Grid").data("kendoGrid"); grid.removeRow(grid.select()); 如果您还没有手动选择它,可以通过js来完成: grid.select(-1); //this cleans the current selection var tr = $("#Grid").find("tbody").find("tr")[index]; // 0 based index of the item yo ...
-
您可以填充kendo数据源的新实例,加载数据,然后根据结果执行操作,设置网格的数据源。 也许是这样的: var dataSource = new kendo.data.DataSource({ transport: { read: { type: "POST", dataType: "json", url: 'Item/GetItems/', data: { number: number }, } } }); 然后从服务器获取数据并 ...
-
Kendo网格上的两种编辑模式(Two edit modes on a Kendo grid)[2020-01-12]
你有没有尝试过ForeignKey专栏呢? 你可以在这里看到它的演示: http : //demos.kendoui.com/web/grid/foreignkeycolumn.html 我不确定如何同时拥有两种编辑模式,但我确信你可以在下拉值改变时编写一些自定义的javascript来监听。 What I wanted was not possible per Kendo UI support. I did manage a work around though. The grid must be in ... -
Kendo UI Grid内联编辑(Kendo UI Grid inline edit)[2022-04-30]
由于您的数据实际上嵌套在list元素上,因此您需要添加到架构data: "list" 。 它应该看起来像: schema: { data:"list", model: { id: "GeoId", fields: { GeoId: { editable: false, nullable: true }, ContentId: { editable: false, nullable: true }, ... -
在Kendo网格上应用rowTemplate而不会覆盖当前(Apply rowTemplate on Kendo grid without overriding current)[2023-02-04]
好吧,似乎通过它如何开发Kendo,一旦你设置了行模板,你需要全力以赴。没有部分模板或包装器这样的东西。 更多信息在这里 。 Well, it seems that by how Kendo it's developed, once you set up a row-template, you need to go all in. There is not such thing as partial template or wrapper. More information here.