How do I turn data into JSON and pass it to the backend through Ajax

0 favourites
  • 6 posts
From the Asset Store
Assets for creating mountains and ravines environments
  • Thank you for your view. For example, when a user logs in, he / she transfers the account password to the background through JSON format. How to implement it through post? I tried to put the JSON format {Username: username, phone: Phone} into data, but the background didn't receive it. At present, I can only splice the value behind the website. Is it my writing problem, or is there any other way?

  • First, you are already passing user_phone and password in URL parameters, your php script can access them from there, you don't need to send them again in Data field.

    If you need to send data in JSON string, you should wrap all text values in quotes, for example:

    "{'phone':'" & user_phone & "', 'password':'" & password & "')"
    or 
    "{""phone"":""" & user_phone & """, ""password"":""" & password & """)"
    

    Or simply add these values into JSON object and use JSON.ToCompactString expression, it will format the string correctly for you.

  • Thank you very much for your help, which has solved my big problem. I tried character splicing before, but it failed.

  • I tried to use the JSON method to pass values, and found that the value must be added "" to take effect, otherwise it will be null. So I created ll and RR to represent "and". Then I spliced them together to display them normally. I don't know if it's caused by my wrong use. Please be able to answer my doubts. Thank you

    When I don't add "", I can't put the value in JSON. The displayed value is null.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't know what you are doing wrong. Simply setting JSON key "name" to TextBox.text works for me, the resulting compact string looks like this:

    {"name":"John"}

  • I don't know what the problem is. I used the 180beta version! Is it related to the region? I'm from China.

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