weixin_33709609 2014-05-14 05:54 采纳率: 0%
浏览 60

AJAX变量为html

If I have this code in AJAX success..

success: function(msg) {
    var msg = $.parseJSON(msg);
        new_name = msg.Name;
        var html_new_name = new_name;
        $('#new_project_name').append(html_new_name);
        $('#myModalAlertSuccess').modal('show');
    }

How can I access the variable html_new_name in AJAX to HTML..Like this:

<a href='<?php echo base_url('generator/view_generate'.$html_new_name) ?>'>
  <button type="button" class="btn btn-primary" id="view" data-dismiss="modal">
    View
  </button>
</a>

So that I can use the variable html_new_name to another method in Controller.

Or if it is not possible? Is there any other way?

  • 写回答

2条回答 默认 最新

  • weixin_33720078 2014-05-14 06:09
    关注

    AJAX success..

    success: function(msg) {
        var msg = $.parseJSON(msg);
            var link = $("#myLinke").attr('href');
            $("#myLinke").attr('href', link + msg.Name)                
    
        }
    

    html :

    <a id="myLinke" href='<?php echo base_url('generator/view_generate') ?>'>
      <button type="button" class="btn btn-primary" id="view" data-dismiss="modal">
        View
      </button>
    </a>
    
    评论

报告相同问题?