繁体   English   中英

尝试同时使用window.location和replaceWith()

[英]Trying to use window.location and replaceWith() in the same time

我有一个链接,单击该链接应会生成PDF文档并更改其自身的文本。

这是我的JS函数:

function clander(){

  window.location="orders/issueBill/order_id/"+order_id;

  $('#jander').replaceWith('pdf just generated');

}

链接:

<a href="#" id="jander" onClick='clander()'>click here</a>

那个行动:

public function executeIssueBill(sfWebRequest $request) {

//here is the code that generates the pdf.

}

问题:当我单击链接时,它会生成pdf,但链接的文本不会更改。 仅当我删除window.location...行时,它才会更改文本。

我的代码的原因在这里

任何想法?

问候

哈维

问题在于它永远不会涉及到这一部分:

$('#jander').replaceWith('pdf just generated');

它将用户重定向到"orders/issueBill/order_id/"+order_id ,这是一个不同的页面,因此它不记得状态。

我猜您最好的选择是将参数传递到新页面(即"orders/issueBill/order_id/"+order_id+"?pdf_generated=1" )-这样一来,它便知道生成了pdf,并且您可以相应地更改链接。

我认为这是js函数中语句的顺序。 如果您以其他方式更改顺序,则应该可以正常工作,如下所示:

<script>

function clander(){

    document.getElementById('jander').innerHTML = 'pdf just generated';
    window.location="orders/issueBill/order_id/"+order_id;

}

</script>

<a href="#" id="jander" onClick='clander()'>click here</a>

最好,Kamran

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM