📜  js ajax 接收 html - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:47.531000             🧑  作者: Mango

代码示例1
$.ajax({
      type: 'POST',
      url: "",
    contentType: 'application/json; charset=utf-8'
      // Set your dataType to either 'html' or 'text'.
    // Keep in mind: dataType is for receiving,
    // contentType is for sending
      dataType: 'html',
      data: { example: 1, id: "0x100"},
    // Note: the data above is used in sending,
    // data below is a variables that stores received data
      success: function (data){
         // Suppose you have an html element, where you want to append 
         // the response:
         $('#').html(data);
          // .html(data) overwrites existing data
        // Use .append(data) to add response without overwriting!
      }
});