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
Post a Comment