Send POST data using XMLHttpRequest

前端 未结 13 1477
说谎
说谎 2020-11-21 04:27

I\'d like to send some data using an XMLHttpRequest in JavaScript.

Say I have the following form in HTML:

<         


        
13条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-21 04:53

    Here is a complete solution with application-json:

    // Input values will be grabbed by ID
    
    
    
    // return stops normal action and runs login()
    
    
    
    

    Ensure that your Backend API can parse JSON.

    For example, in Express JS:

    import bodyParser from 'body-parser'
    app.use(bodyParser.json())
    

提交回复
热议问题