English 中文(简体)
如何避免一种形式状态,以免在时间结束时使我屈服于 submit?
原标题:How to save a form state from a jquery that disables my submit button when timer ends?

我在我的网站上有一只手脚印,把一个时间推到零,然后展示一个信息,使我的台子失去作用,以防止更多的数据输入我的数据库。 然而,当页重载时,当时间者完成时,我不得不去除提交纽特。 我知道,需要拯救形式状态,但我知道如何做到这一点?

这是我解说的残script的一部分。

function CountBack(secs) {
if (secs < 0) {
document.getElementById("cntdwn").innerHTML = FinishMessage;
$("input[type=submit]").attr("disabled", "disabled");


return;

这是我的一种形式。

<form id="MakeBid" action="MakeBid.php" method="POST">
<input type="hidden" name="propertyID" value ="1"/>
<div>Bid Now <input type="text" name="pricesoldfor"/></div> 
<input id = "submit" input type="submit" value="Submit" /> 
</form>

成就

最佳回答

我的建议:

  1. Keep the state on the server.
  2. Bef或e sending the f或m to the client, check if (s)he is allowed to write to your database.
  3. Send the f或m with embedded parameter like MyF或m.noSubmit = true;.
  4. Optionally - poll the server and check if it accepts m或e data.

So, assuming you have PHP on the server, you get something like this:

var MyF或m.noSubmit = <?php echo ($MyDB->acceptsData()) ? "false" : "true"; ?>

<input <?php if (!$MyDB->acceptsData()) {echo "disabled="disabled"";} ?> />

当然取决于你们的执行情况。

The above suggestion will w或k on page reload.

问题回答

您可使用<代码>.serialize(>)方法储存您的表格。 之后,你可以使用淡化石块,使(restore)帝国化。

http://archive.plugins.jquery.com/project/deserialize”rel=“nofollow”>http://archive.plugins.jquery.com/project/deserialize

储存

var formState = $("#MakeBid").serialize();

然后将formState作为 co的载体储存。 网页重载后,你可以读到表格式国家,并从宇宙库中解脱。

恢复形式:

$("#MakeBid").deserialize(formState ,
callback: function(name,value){
$( input[name=" +name+ "] ).val(value);
});

您一定能够提交,或者不列入server-side。 如果提交了足够的数据,使服务器上的形式失去作用,而且听起来不错,那么你就不得不担心。

缩略语:

If enough datas are in the database, don t write to it and leave the script
Else write normally, it means the countdown s not reached the end

由于即使表格残疾,我仍能够提供并发送一些数据。

www.un.org/spanish/ecosoc 从来没有信任客户。

https://github.com/carhartl/jquery-cookie/blob/master/jquery.cookie.js”rel=“nofollow”

And then, after the time spent set a cookie: $.cookie( block , 1 )

在您的首页上,你可以启动或停止提交,具体如下:

jQuery(function($){
  if($.cookie( block ))
    $( #submit ).attr("disabled","disabled");
});

但铭记这一方法只是客户一方,因此,如果你想要防止某一表格被贴出,则不会利用这一方法确保网站安全。

EDIT: Here the full solution

var bidDuration = 10000
  , bidFinishedMessage = "C est fini !!";

jQuery(function($){        
  var finishBid = function() {
    $("#submit").attr("disabled", "disabled");
    $("#cntdwn").html(bidFinishedMessage);
    $.cookie( blockBid , 1 );
  };

  if($.cookie( blockBid ))
    $( #submit ).attr("disabled","disabled");

  setTimeout(finishBid, bidDuration);
});





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签