Coder Social home page Coder Social logo

Comments (4)

sarfata avatar sarfata commented on August 25, 2024

It will post the data as json but not as urlencoded form data. This is a common way to do this for json webservice but maybe not what you were expecting.

See: https://github.com/pebble/pebblejs/blob/develop/src/js/lib/ajax.js#L84-L86

from pebblejs.

Meiguro avatar Meiguro commented on August 25, 2024

Thanks for responding Thomas.

That's right, the 'json' type is when both client and server use json. Similarly, 'form' is when both use form. Thus type is a convenience parameter for when only a single format is used throughout. In the case of sending form data and receiving json data, leaving the type undefined or specifying 'text' and using JSON.parse for received data is best. It can be annoying to have to repeat this pattern so wrapping this in a helper function might help.

I'll be sure to make this more clear in the documentation.

from pebblejs.

Drumkruk avatar Drumkruk commented on August 25, 2024

Interesting. It would be good to put it in the documentation that the output is also changed by the 'type'. I am now storing the data from the ajax request in php with the following code:

json_decode(file_get_contents('php://input'), true);

from pebblejs.

Meiguro avatar Meiguro commented on August 25, 2024

Thanks, the documentation has been updated! It sort of shoves a lot of into into that little box -- I should structure it better in the future.

from pebblejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.