jQuery posting JSON -


update: pass var value server

hello, same old, same old ... :)

i have form called <form id="testform" action="javascript:test()"> , code area called <code id="testarea"></code>

i using code stringify , display data in code area:

var formdata = form2object('testform'); document.getelementbyid('testarea').innerhtml = json.stringify(formdata, null, '\t'); var value = json.stringify(formdata, null, '\t'); 

what want send data json file. i've been working on project : http://ridegrab.com/profile_old/ , if press submit query button see head of page populate.

also want use piece of script send data:

    function authenticate(username, password) {     $.ajax     ({         type: "post",         //the url want sent username , password         url: 'username:password@link server/update',         datatype: 'json',         async: false,         //json object sent authentication url         data: '{"username": "' + username + '", "password" : "' + password + '"}',         success: function () {          alert("thanks!");          }     }) } 

again, want able send json data server. server set update or post data in right place.

your 'data' should stringified javascript object:

data: json.stringify({ "username": username, "password" : password }) 

or, send data form, pass formdata, this:

data: json.stringify(formdata) 

there's more detailed answer similar question here: jquery ajax posting json webservice


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -