Locked icon Post JSON data with AJAX object

From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
    • Post link icon

    Hello,

    I'm attempting to use the AJAX object to post JSON data.

    The write-up for the AJAX object mentions that the URLEncode system expression should be used for urlencoded content, but is there a similar expression for JSON content?

    If not, any reason manually formatting the data wouldn't work? I understand the double quotes requirement. For example, in the data field:

    {"title":"Hello back at you"}

    would need to be:

    {""title"":""Hello back at you""}

    Thanks for any insights.

    • Post link icon

    Correct me if I am wrong, but the double quote requirement should be used if you enter manually a string (as the " is understanding as the beginning/end of a string), otherwise, there is no need to double quote, since the variable is already a full string

    I can be wrong.

    • Post link icon

    Right, this assumes I was entering the data in the data field itself (which expects a string). The first set of quotes is a requirement of the JSON data format.

    • Post link icon

    You should URLEncode any data you post, regardless of the format of the data. So you should still URLEncode your JSON.

    • Post link icon

    Ah, thank you very much. This explains a lot.

    • Post link icon

    Hmm, the target of my AJAX post is expecting application/json as its content-type.

    It looks like the AJAX post content type in C2 uses application/x-www-form-urlencoded.

    Is this correct? If so, anyway to change the content-type for Post action in the AJAX object?

    • Post link icon

    To answer my own question, yes.

    To change the content-type in the AJAX plugin, you merely need to edit the AJAX runtime.js file and replace application/x-www-form-urlencoded with the content you need (in my case application/json).

    • Post link icon

    You should never edit the source of the official plugins, you will cause really annoying compatibility problems for yourself. Isn't it possible to read the data on the server-side and convert it to JSON even with that MIME type?

    • Post link icon

    How do I change that code?

    • Post link icon

    This thread is 6 years old and is now out of date. Use the 'Set request header' action to change the Content-Type.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
    • Post link icon

    You saved me, thank you so much

    • Post link icon

    Okey so, I made that, I'm assuming on the value field I have to write the data I want to post, but how I send this data to a URL? If I use the "post to URL" how I should use it to send the previous json?

    • Post link icon

    Please start a new thread, this thread is 6 years old and out of date.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)