3

Serialize the entry with the html value using an ajax query

 2 years ago
source link: https://www.codesd.com/item/serialize-the-entry-with-the-html-value-using-an-ajax-query.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Serialize the entry with the html value using an ajax query

advertisements

I used jquery.ajax post to send the data to the server using c# but it handles an error here's my code

$(function(){
  $('#frmSubmit').on('submit', function(e){
    e.preventDefault();
    var frm = $(this);

    $.ajax({
      url: frm.attr('action'),
      type: frm.attr('method'),
      data: frm.serialize(),
      dataType: 'JSON',
      success: function(){
        alert('success');
      },
      error: function(){
        alert('error');
      }
    });
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<form id="frmSubmit" method="post" action="/announcement/create">
  Title:<br/>
  <input type="text" id="title" name="title" /> <br/>
  Body:<br/>
  <textarea id="body" name="body"></textarea> <br/>

  <button type="submit">submit</button>
 </form>

My problem is when I input a html code on the textarea the result is error but when I input a normal text the result is okay, so my conclusion is that the serialized form won't accept any html code, I don't know why. please help me.

New Update Actually... I'll use this method in order for me to store html content using trix-editor (WYSIWYG).. here's the link but the problem is stated above... please help me to solve this guys...

Your response would be very much appreciated, thank you in advance


You need to use HTML Entities in your html text which you are pasting in your text area. Signs like http://www.w3schools.com/html/html_entities.asp

I have not used it myself. But after some googling I found that you need to Encode your html text into html entities before posting it. There are methods written by someone to encode and decode it (https://gist.github.com/CatTail/4174511).

hope it helps.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK