【问题标题】:Creating and generating HTML File with jquery Ajax使用 jquery Ajax 创建和生成 HTML 文件
【发布时间】:2016-08-30 15:08:42
【问题描述】:

在这里,我想通过使用这个 ajax 将这个小数据创建到像 nafiz 这样的 HTML 文件中。并且通过单击按钮调用 ajax 函数。但它不起作用

<script type="text/javascript">


           function GetHTmlGenerateList() {
              // var crthtml = $("#TextArea1").val();
               var crthtml = "<b>nafiz</b>";
               GenerateHtmlList = new HtmlGenerate(crthtml);
               alert(GenerateHtmlList);

               $.ajax({
                   beforeSend: function () {
                       // show image here
                       $('#loadBusy').show();
                   },
                   complete: function () {
                       // hide image here<a href="../../RelatedCategory/">../../RelatedCategory/</a>
                       $('#loadBusy').hide();
                   },
                   type: "POST",
                   contentType: "application/json; charset=utf-8",
                   url: window.location.origin + "/Service/AdminService/CategoryHtmlGenerator.asmx" + "/InfoGenerate",
                   //paramiter Input
                   data: JSON.stringify({ aGenerateHtmlList: GenerateHtmlList }),
                   dataType: "json",
                   async: true,
                   cache: false,
                   success: function (data) {
                       var resultData = result['d'];
                       document.getElementById("lblSystemMessage").innerHTML = "Saved";

                   },
                   error: function (x, e) {
                       console.log(x);
                       console.log(e);
                   }
               });
           }

   </script>

方法如下

public void InfoGenerate(GenerateHtmlList aGenerateHtmlList)
    {

   // GenerateHtmlList aGenerateHtmlList = new GenerateHtmlList();
    string FileName = "nafiz.html";
    string HTMLGenarator = "";

    HTMLGenarator = "<html>" +
                     "<body style='margin:0px 0px 0px 0px!important;'>" +
                     "<div style='float:left;width:100%!important;height:100%!important;margin:0px;padding:0px;'>" +
                 aGenerateHtmlList.Createhtml
                    +
                     "</div>" +

                     "</body>" +
                     "</html>";



    string pathOfFile = Server.MapPath(@"../../Images/Files/HTML/" + FileName);
    if (File.Exists(pathOfFile))
    {
        this.CopyFile(FileName);
        this.DeleteFile(FileName);
    }
    this.CreateHTMLFile(FileName, HTMLGenarator);

}

公共类 GenerateHtmlList { 公共字符串 Createhtml { 获取;放; } }

而 CREATEHTML 方法是

public void CreateHTMLFile(string HTMLFileName, string Content)
{
    string destinationPath = Server.MapPath(@"../../Images/Files/HTML/" + HTMLFileName);
    string htmlDocument = Content;
    FileStream fileStream = File.OpenWrite(destinationPath);
    StreamWriter streamWriter = new StreamWriter(fileStream, Encoding.UTF8);
    streamWriter.Write(htmlDocument);
    streamWriter.Close();
}

我正在初始化这个

<script type="text/javascript">
       function HtmlGenerate(crthtml) {
           this.Createhtml = crthtml;
       }
   </script>

【问题讨论】:

  • 真正的问题是什么?
  • 我的问题是 html 文件没有在我的目标文件夹中创建,在我的 ajax 错误中说它。

标签: javascript c# jquery html ajax


【解决方案1】:

要么您没有显示它,要么您的代码中没有将 onClick 操作分配给按钮的部分。这就是我从您的问题中了解到的,当您单击按钮时没有调用该函数。

【讨论】:

  • 你是说这个吗? owenek1 你是说我的方法和函数在那个 ajax 中不起作用
猜你喜欢
  • 2020-02-26
  • 2014-04-21
  • 1970-01-01
  • 1970-01-01
  • 2015-08-05
  • 1970-01-01
  • 1970-01-01
  • 2013-10-13
  • 1970-01-01
相关资源
最近更新 更多