JavaScript / jQuery为什么这不起作用?(JavaScript / jQuery why doesn't this work?)
function checkSession(){ $.ajax({url: "session.php", success: function(data){ if( data == 1){ var postFilen = 'msg.php'; $.post(postFilen, function(data){ $("#msg").html(data).find("#message2").fadeIn("slow") } } else { $('#message2').hide(); } }}); // setInterval('checkSession()',1000); }
基本上,这是在session.php中检查数据是否为1,如果是,它应该在#msg中运行msg.php的div#message2
function checkSession(){ $.ajax({url: "session.php", success: function(data){ if( data == 1){ var postFilen = 'msg.php'; $.post(postFilen, function(data){ $("#msg").html(data).find("#message2").fadeIn("slow") } } else { $('#message2').hide(); } }}); // setInterval('checkSession()',1000); }
Basically, this is checking if data is 1 in session.php, and if it is, it should run msg.php´s div #message2 in #msg
原文:https://stackoverflow.com/questions/2329860
最满意答案
由于
one
是ArrayList,因此只能将它作为参考传递。 你现在显然将它作为引用来引用构造函数。 你可能不需要那个ref
。但是请展示你想要完成的更完整的想法。
编辑:
看完你的C课后,不需要
ref
。c
将共享A调用的ArrayList的实例。这似乎归结为.NET中的一般referencetype / valuetype问题。 总结:
- 对象的实例没有名称,并且根本无法(物理上)作为参数传递。
- 你总是通过引用访问实例。 在你的代码中,
one
(2x),two
local
都是对Arraylist实例的引用。- 引用本身的行为类似于值类型,即赋值意味着复制。
要了解有关referencetypes / valuetypes的更多信息,请搜索“复制语义”,并避免以'valueetypes存在于堆栈中'为开头的帖子。
Since
one
is an ArrayList, you can only pass it as a reference. You are now apparently passing it as a reference-to-a-reference to the constructor. You may not need thatref
.But please show a more complete idea of what you are trying to accomplish.
Edit:
After seeing your C class, there is no need for the
ref
.c
will share the instance of the ArrayList that A callsone
.This seems to boil down to the general referencetype/valuetype issue in .NET. To summarize:
- instances of objects do not have a name and cannot (physically) be passed as parameter at all.
- you always access an instance through a reference. In your code,
one
(2x) ,two
,local
are all references to Arraylist instances.- the references themselves behave like valuetypes, ie assignment means copying.
To learn more about referencetypes/valuetypes, search for 'copy semantics' and avoid postings that start with 'valuetypes exist on the stack'.
相关问答
更多-
在需要时通过引用传递,即,当您需要重新分配引用以引用其他对象时: void ByRef(ref object o) { o = new object(); } 如果方法保证设置o则将其作为out参数传递。 默认语义(通过引用副本传递)适合大多数需求,因为您通常只修改对象的字段/属性。 如果参数是值类型,那么您需要使用ref以调用者看到的方式改变参数。 我的问题是; 你为什么要改变构造函数的参数? 这对我来说有点奇怪。 Pass by reference when you need to, i.e. ...
-
您可以使用简单的Action void AddMethod(Action action) //or void AddMethod(Func
fxn) { } 并打电话给 AddMethod(()=>Test(obj)); 要么 AddMethod(()=>Test(obj1,obj2)); - 编辑 - AddMethod(() => Math.Max(1,3)); AddMethod(() => (int)Math.Sqrt(4)); AddMethod(() => ... -
如果他们没有共同的基类或接口,我可以想到两种方法来实现你想要的: 传递一个object 让你的方法获取一个object参数并使用is运算符找出你得到的东西,也许是这样的: public void CallMethod(object service) { if (service is Localservice) ((Localservice)service).CallMethod(); else ((Amazonservice)service).CallMeth ...
-
通过CodingK0ala的链接,我终于能够解决它了,即使我之前看过这篇文章并且没有找到答案。
谢谢。 编辑:其实我不知道那时看起来如此难以理解。 :) With CodingK0ala's link I finally were able to resolve it, even though I looked in the article before and did not find the answer the ... -
mi无效。 要获取私有方法,您需要传递BindingFlags.Instance | BindingFlags.NonPublic BindingFlags.Instance | BindingFlags.NonPublic 。 mi is null. To get a private method, you need to pass BindingFlags.Instance | BindingFlags.NonPublic.
-
你的例子有点不对(也可能不会工作,但语义/意图是正确的): private Closure
- closure = null; public IEnumerable
- GetDayData(DateTime day) { if (closure == null) { this.closure = new Closure
- () { Predicate = i => i.IsValidFo ...
- closure = null; public IEnumerable
-
由于one是ArrayList,因此只能将它作为参考传递。 你现在显然将它作为引用来引用构造函数。 你可能不需要那个ref 。 但是请展示你想要完成的更完整的想法。 编辑: 看完你的C课后,不需要ref 。 c将共享A调用的ArrayList的实例。 这似乎归结为.NET中的一般referencetype / valuetype问题。 总结: 对象的实例没有名称,并且根本无法(物理上)作为参数传递。 你总是通过引用访问实例。 在你的代码中, one (2x), two local都是对Arraylist实例 ...
-
如何组合类: public class Sheet { public string SheetName { get; set; } public string SheetData { get; set; } public List
ParameterData = new List (); } public class ParameterData { ... -
C#参考参数的用法(C# reference parameter usage)[2022-04-17]
只要用一堂课。 并完全避免out参数: class TransactionResult { public ListItems { get; set; } public int TotalTransaction { get; set; } public int OutTransaction { get; set; } public int TotalRecord { get; set; } } public Transac ... -
复制开销 这两种方法都会将输入字符串中的数据复制到类变量中: QString name; //member variable of TestClass class void TestClass::setName1(const QString & name) { this->name = name; } void TestClass::setName2(const QString name) { this->name = name; } 在第二个中,将首先在堆栈上创建QString的副本 ...