刷新数据不显示后的Ajax` <div>`

时间:2018-03-28 17:37:39

标签: javascript jquery ajax

我在更新数据库中的数据后尝试更新<div>,但在<div>刷新后,它不会显示数据。这是我的代码:

<div class="tab-pane active" id="receivedHere" style="width: 100%;">

  @foreach($compose as $compose)
  @if($compose->active == 1)
    ......
     <input type="hidden" id="id" value="{{ $compose->id }}">
     <img src="/public/images/EyePublic.svg" 
     onclick="changeComposer('0','{{ $compose->id }}')"></span>
    ......
  @else($compose->active == 0)
   ....
       <input type="hidden" id="id" value="{{ $compose->id }}">
       <img src="/public/images/EyePrivate.svg" 
       onclick="changeComposer('1','{{ 
       $compose->id }}')"></span>
    .....

  @endif
 @endforeach

</div>

我的ajax代码是

function changeComposer(argument, id) {
  var link = "{{ URL::to('/') }}/public/images/settingLoader.gif";
  document.getElementById('receivedHere').innerHTML = '<center><img 
  src="'+link+'"></center>'; //for replacing the div to img after click and image will remove after ajax success.

  $.ajax({
    type: "POST",
    url: "{{URL::to('/')}}/updateComposer",
    data: {id : id, update : argument},
    success: function(){
      $("#receivedHere").load(" #receivedHere");
    }
  });
 }

已更新的部分正在运行,但成功后,重新加载div并且未显示更新的数据...有任何建议吗?

我的控制器更新了

public function updateComposer(Request $request) {
    $user_id = UserGratitude::where('user_id', Auth::user()->id)->first();
    if($user_id){
        UserGratitude::where('id', $request->id)
            ->update([
                'is_active' => $request->update
            ]);
        return response('success', 200);
    }
}

2 个答案:

答案 0 :(得分:0)

您可以使用{/ 1}}这样的方法

'C:\Anaconda2\Scripts\activate.bat' is not recognized as an internal or external command, operable program or batch file.

这是JS流程

html

答案 1 :(得分:0)

如果您要过滤掉部分页面,则需要在.load()的来电中使用实际网址。
您可以使用location来获取当前页面的网址。

$("#receivedHere").load(location.href + " #receivedHere");