Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •