Post in two tables simultaneously in AJAX

1

The code below it is working, however my question is: Is there any way to do a post on two different addresses simultaneously using that same code without repeating it?

For example, in the code below I insert data into a table, but there are other fields on my page that go to another table. In this situation is there any artifice that can be done in that same code or would I have to repeat it and insert the data from the other table?

$.ajax({  

        url:'http://localhost:8080/teste/rest/cadastro',  
        type:'POST',
        contentType: "application/json",
        data :  dados,      
        dataType: 'JSON',
        success: function(data) { 

            }  
    }); 

Thank you in advance!

    
asked by anonymous 03.02.2017 / 12:52

1 answer

2

You can not use more than one url in the same request. Alternatively, you can use a function to send the request from a given URL, thus not repeating the code.

Example:

    function sendMyAjax(URL_address){
       $.ajax({  
            url: URL_address,  
            type:'POST',
            contentType: "application/json",
            data :  dados,      
            dataType: 'JSON',
            success: function(data) { 

                }  
        }); 
    };

sendMyAjax('http://localhost:8080/teste/rest/cadastro');
sendMyAjax('http://localhost:8080/teste2/rest/cadastro2');

Source: Multiple url in same ajax call? is this possible?

    
03.02.2017 / 13:03