I'm having issues w/ retrieving params from my jquery modal form. I've
whittled it down the page to make it easier for debugging but no such luck.
This is my app.js
var app = require('http').createServer(handler),
fs = require('fs'),
qs = require('querystring'),
util = require('util'),
url = require("url");
var index = fs.readFileSync('index.html');
app.listen(8080);
function handler(request,response){
console.log(request.method);
switch(request.method){
case 'GET':
handleGet(request,response);
break;
case 'POST':
handlePost(request,response);
break;
default:
//method is not supported
response.statusCode = 405;
response.end();
break;
}
};
var handleGet = function(request,response){
response.writeHead(200, { 'Content-Type': 'text/html' });
response.end(index, 'utf-8');
};
var handlePost = function(request,response){
var fullBody = '';
request.on('data',function(chunk){
fullBody += chunk.toString();
});
console.log(fullBody);
request.on('end',function(){
var formData = qs.parse(fullBody);
fs.writeFile("/tmp/test",JSON.stringify(formData,null,4),function(err){
response.statusCode = (err === undefined) ? 500 : 201;
response.end();
});
});
};
index.html
<html>
<head>
<link rel="stylesheet"
href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<link rel="stylesheet" href="/resources/demos/style.css" />
<script
src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
<script
src='http://jquery-json.googlecode.com/files/jquery.json-2.2.min.js'></script>
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script src='http://datejs.googlecode.com/svn/trunk/build/date.js'></script>
<script>
$(function() {
$( "#dialog-form" ).dialog({
autoOpen: false,
height: 675,
width: 325,
modal: true,
buttons: {
"Enter trade": function() {
$('#tradeForm').submit() ;
$('#tradeForm').each(function(){
this.reset();
});
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
$( "#add-trade" )
.button()
.click(function() {
$( "#dialog-form" ).dialog( "open" );
});
});
</script>
<style>
body { font-size: 75.5%; }
label, input { display:block; }
input.text { margin-bottom:12px; width:95%; padding: .4em; }
fieldset { padding:0; border:0; margin-top:25px; }
h1 { font-size: 1.0em; margin: .6em 0; }
div#users-contain { width: 750px; margin: 20px 0; }
div#users-contain table { margin: 1em 0; border-collapse: collapse;
width: 100%; }
div#users-contain table td, div#users-contain table th { border:
1px solid #eee; padding: .6em 10px; text-align: left; }
.ui-dialog .ui-state-error { padding: .3em; }
</style>
</head>
<body>
<button id="add-trade">Add Trade</button>
<div id="dialog-form" title="Enter trade">
<form id="tradeForm" method="post" action="#">
<fieldset>
<label for="tradeId">Trade Id</label>
<input type="text" name="tradeReference" id="tradeReference"
class="text ui-widget-content ui-corner-all" />
</fieldset>
</form>
</div>
</body>
</html>
Nothing is in the request body or request params. If I use a normal form,
then everything works fine. Any ideas?
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en