Hello and welcome to our community! Is this your first visit?
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
    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?


    Steve Garlick

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    London, UK
    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:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.js"></script>
    <script type="text/javascript">
    var data = {
    		$.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;


    Posting Permissions

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