Jump to content

Long Markdown Previews are broken when using Ajax GET. It should do a POST instead.


infomaniac50

Recommended Posts

For whatever reason the Markdown preview is broken on our server when content is submitted with a GET request. I suspect the URL is too long and the server is rejecting it.

 

When the preview is requested the content pane shows up empty.

 

Raw JSON from the GET request.

{"body":"\u003Cdiv class=\u0022markdown-content\u0022\u003E\n\u003C\/div\u003E"}

 

I was able to jerry rig the page to send a POST request to see if that would fix the issue. The code I used to force it to use a POST request is listed below.

 

I have verified that doing a POST instead of a GET request fixes the problem. I would fix it myself but it is an inline script which I assume is embedded in the ionCube encrypted bytecode.

 

We are using the latest version of WHMCS 6.3.1. Our server runs cPanel, Apache 2.4, and WHMCS runs on PHP 5.6.30

 

This sends a plain GET request.

var originalContent = e.getContent(),
               parsedContent;

           jQuery.ajax({
               url: '/admin/supporttickets.php',
               async: false,
               data: {token: '<Dynamic Token Embedded Here>', action: 'parseMarkdown', content: originalContent},
               success: function (data) {
                   parsedContent = data;
               }
           });

           return parsedContent.body ? parsedContent.body : '';
       },

 

This will send a POST request instead of GET.

var originalContent = e.getContent(),
               parsedContent;

           jQuery.ajax({
               url: '/admin/supporttickets.php',
               type; 'POST',
               async: false,
               data: {token: '<Dynamic Token Embedded Here>', action: 'parseMarkdown', content: originalContent},
               success: function (data) {
                   parsedContent = data;
               }
           });

           return parsedContent.body ? parsedContent.body : '';
       },

 

Force All Ajax Requests to use the POST method

$.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
 options.type = "POST";
});

 

While testing I used the example Markdown from the help popover.

 

Example Markdown

**bold**
*italics*
~~strikethrough~~
Headers

# Big header

## Medium header

### Small header

#### Tiny header

Lists

* Generic list item
* Generic list item
* Generic list item

1. Numbered list item
2. Numbered list item
3. Numbered list item
Links

[Text to display](http://www.example.com)
Quotes

> This is a quote.
> It can span multiple lines!

Tables

| Column 1 | Column 2 | Column 3 |
| -------- | -------- | -------- |
| John     | Doe      | Male     |
| Mary     | Smith    | Female   |

Or without aligning the columns...

| Column 1 | Column 2 | Column 3 |
| -------- | -------- | -------- |
| John | Doe | Male |
| Mary | Smith | Female |

Displaying code

`var example = "hello!";`
Or spanning multiple lines...

```
var example = "hello!";
alert(example);
```

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated