Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-08-2009, 05:44 AM   PM User | #1
Steve Garlick
New to the CF scene

 
Join Date: Dec 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Steve Garlick is an unknown quantity at this point
Help with multiple submit calls.

Hi , first post.

I'm trying to send data back to a database that's encoded in javascript objects on a page.

I've used this approach to fill in a pseudo form and submit the results to several php files to update the database. Everything works fine, done one at a time. When I call this type of function inside another loop to feed multiple objects to the database, only the first record is inserted. I'm wondering if there are latency issues with multiple submits?

function postwith (to,p) {
var myForm = document.createElement("form");
myForm.method="post" ;
myForm.action = to ;
for (var k in p) {
var myInput = document.createElement("input") ;
myInput.setAttribute("name", k) ;
myInput.setAttribute("value", p[k]);
myForm.appendChild(myInput) ;
}
document.body.appendChild(myForm) ;
myForm.submit() ;
document.body.removeChild(myForm) ;
};

Maybe I'm barking up the wrong tree. Is there an easier way to pipe arrays of javascript objects back into multiple database tables?

Regards,

Steve Garlick
Steve Garlick is offline   Reply With Quote
Old 12-08-2009, 11:56 AM   PM User | #2
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
I'd suggest two things.

First, use Firebug to view exactly what's being sent over HTTP, to where. That might give you an idea of what, if anything, is happening on the server.

Second, what you're trying to do seems to be a convoluted way of mocking up an AJAX call; you'd be better off, it looks from here, dropping everything into AJAX. Since you've asked this in the javascript frameworks forum, here's how you might do it with one common JS framework, jQuery:

Code:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.js"></script>
<script type="text/javascript">
var data = {
	animal:"dog",
	mineral:"salt",
	vegetable:"jordan"
};
$(document).ready(function(){

	$('#myform').submit(function(){
		$.get('http://www.site.com/script1.php', data, function(rv){
			console.log('Script 1 response:' + rv);
		});
		$.get('http://www.site.com/script2.php', data, function(rv){
			console.log('Script 2 response:' + rv);
		});
		return false;
	});
	
});
</script>
Spudhead is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:50 PM.


Advertisement
Log in to turn off these ads.