如何更换的含量小于TD>和< DIV>在Ajax响应新的内容?含量、内容、TD、lt

2023-09-10 17:47:47 作者:挽梦忆笙歌。

您的理解我的问题,我已经把这里只必要code。

For your understanding my issue I've put in here only the necessary code.

HTML code:

HTML Code :

<td style="text-align:center" id="brand_image_td_101">Some text goes here</td><!-- This is the td whose content need to be replaced with new content-->

<div id="brand_101"><!-- This is the div whose content need to be replaced with new content-->    
  <a href="#" id="promotion_status_101">
  <button type="button" class="btn btn-default brmodalbtn" data-toggle="modal" data-target="#BrandImageModal" id="101">On</button>
  </a>
</div>

将显示在点击上面的div按钮的模态对话框,AJAX请求转到PHP页面,从那里的错误或成功的消息来了,等等等等。

The modal dialog is displayed on click of the button from above div, AJAX request goes to PHP page, from there error or success message comes, etc. etc.

一切正常到这里。我现在面临的问题是在更换了上述&LT的内容; DIV ID =brand_101&GT; 。我想更换上面的内容&LT; D​​IV ID =brand_101&GT; 与以下内容:

Everything works fine till here. The issue I'm facing is in replacing the content of above <div id="brand_101">. I want to replace the content of above <div id="brand_101"> with following content :

<td style="text-align:center" id="brand_image_td_101"><img src="https://m.xsw88.com/allimgs/daicuo/20230910/783.png.jpg" width="80" height="80"></td><!-- This is the new td content-->

<div id="brand_101"><!-- This is the new div content-->
  <a href="#" id="promotion_status_101" onClick="change_promotion_status('http://web_prj.com/pqr.php', 'promotion_status', '101', '0'); return false;">
  <button type="button" class="btn btn-default">Off</button>
  </a> 
</div>

这件事我想实现jQuery函数的成功响应。但我不明白我应该如何实现这一目标。

This thing I want to achieve in jQuery functions's success response. But I'm not understanding how should I achieve this.

以下是jQuery的AJAX功能,我已经写的:

Following is the jQuery AJAX function that I 've written:

$('#form').submit(function(e) {
  var form = $(this);
  var br_id = $('#brand_id').val();//This variable contains value 101
  var status = '0';
  var module_url = $('#module_url').val();//This variable contains value http://web_prj.com/pqr.php
  var upload_url = $('#upload_url').val();//This variable contains value http://web_prj.com/pqr.php/uploads/a123.jpg
  var formdata = false;
  if(window.FormData) {
    formdata = new FormData(form[0]);
  }

  var formAction = form.attr('action');

  $.ajax({
    type        : 'POST',
    url         : 'manufacturers.php',
    cache       : false,
    data        : formdata ? formdata : form.serialize(),
    contentType : false,
    processData : false,

    success: function(response) { 
      if(response.error == 0) {  
        $('#messages').addClass('alert alert-danger').text(response.error_message);

      } else { 
        $('#BrandImageModal').modal('hide');
        //location.reload();       
      }
    },
    dataType:"JSON"
  });
  e.preventDefault();
});

我应该如何更换使用AJAX功能的变量值,这样我可以得到内容上面创建?和新内容的内容

How should I replace the contents of and with new content created using the variables' values in AJAX function so that I could get the content as above?

推荐答案

也许我misinter preting,但你可以尝试这样的:

Maybe I am misinterpreting, but you could try something like this:

//put the following into the the success function where you want to add new content
// create an string containing the html you want to insert
var newContent = '<a href="#" id="promotion_status_101" onClick="change_promotion_status('http://web_prj.com/pqr.php', 'promotion_status', '101', '0'); return   false;"><button type="button" class="btn btn-default">Off</button></a> ';

// remove old content from the div. Now you just have an empty div
$('#branding-101').html('');
// add the new content to the div
$('#branding-101').html(newContent);

或你需要从响应拉新的价值观?如果是这样的话,你会做同样的事情,只有你会从响应文本串联值生成的字符串。

Or do you need to pull new values from the response? If that's the case, you would do the same thing, only you would build the string by concatenating values from the response text..