简体   繁体   中英

ajax post does not send data

I have this ajax-post:

$.ajax({
  url: Config.Proxy + "ContentPages.aspx?t=save",
  type: "POST",
  contentType: "application/x-www-form-urlencoded",
  data: {
    content: content,
    id: currentPageId,
    active: "true",
    subject: $('#txtSubject').val(),
    webid: webid
  },
  success: function (data, status) {
    // do something
  },
  error: function (xhr, desc, err) {
    // Do something
  }
});

I do a post to an .NET page, so I could use the debug mode to check if the data is send correctly. I use the same code as above for a different page (other url, other data).

When I run the application and save the data I don't come in the debug mode. When I use the same code for the other page, it works fine.

I tried to compare both codes, but they are the same. I have removed some data-items, but it still does not work.

Why? Can anyone give me a hint?

Thanks

  • EDIT * I know why this is happening: CKEditor. As soon as I set the variable "content" to the content of the CKEditor and use the post-call, the debug-mode is not called anymore. Also the form-keys in the code-behind are 0. The question now is how to fix this?

Like said in the edit of my original post: Problem was caused by the content of the CKEditor. I think HTML is not parser/loaded/call-it-what-you-want in an AJAX-post. So, with a little help (and without posting code-behind, that had nothing to do with the problem) I figured it out:

var content = escape(CKEDITOR.instances.editor1.getData());

Put the variable "content" in the data-section of the post and voila! It works like a charm.

On the receiving .NET page in code behind, decode the value:

(HttpUtility.UrlDecode(Request.Form.Get("content").NullSafeString())

Thanks anyway

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM