2017-05-26 19:36
浏览 72

在Laravel中从AJAX更新按钮onClick url

I have a simple form with a "Submit" button and an additional "Add" button in blade template. On form submit there is an ajax callback to a controller which validates provided value. Based on the returned result from the controller, I'd like to change the "Add" button onClick event. Here is blade snip:

<button id="theId" type="button" >Add</button>

Relevant ajax pice:

        success: function(result){
           //Update onClick for the add button
           addButton.onclick=function () {
               //location.href = '';

Based on all the sources either location.href or window.location should redirect me to a different page (in my case just a different subpage) but it does not. After hours of research I thought that I get a wrong button or sth is wrong with the ajax itself but then I added addButton.html line and this works well. What do I do wrong here?

图片转代码服务由CSDN问答提供 功能建议

我有一个简单的表单,其中包含“提交”按钮和刀片模板中的其他“添加”按钮。 在表单提交上,有一个对控制器的ajax回调,它验证提供的值。 根据控制器返回的结果,我想更改onClick事件的“添加”按钮。 这是刀片片段:

 &lt; button id =“theId”type =“button”&gt;添加&lt; / button&gt; 
   \  n 

相关的ajax pice:

 //更新onClick for 添加按钮
 addButton.onclick = function(){
 //location.href =''; 
 window.location =“”; 
 addButton  .html(“aNewName”); 

基于所有来源,location.href或window.location应该将我重定向到不同的 页面(在我的情况下只是一个不同的子页面),但它没有。经过几个小时的研究,我认为我得到一个错误的按钮或者是ajax本身的错误但是后来我添加了addButton.html行,这很有效。 我在这里做错了吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题