Replace DIV with URL to posted data

I’m sure I’m missing something obvious, but I’m a beginner so I just need some help pointing it out. I’ve been stuck on this for a while, sadly, and saw some helpful members here so figured I’d reach out for some assistance.

What I’m trying to accomplish is POSTing data from a form to a database on my server, and once the data is posted, I want the form to be replaced with the DIV “Response” which contains a box with a URL to that data. I assume this can achieved by using the ID of the table entry.

Here is the code for my AJAX post;

$('#secursendmsg').submit(function(){
    var postData = $(this).serialize();
    $.ajax({
        type: 'POST',
        data: postData,
        url: 'http://192.xx.xxx.206/server.php',
        success:
        
        function(data){
            console.log(data);
            $("#content").html('<h3>Test Successful</h3>');
            alert('Test Success');
            
           
             var url = 'http://www.secursend.net'+ID;
            },
    
        
        error: function(){
            console.log(data);
            alert('Test Failed');
        
         }
    });
    return false;
}); 

I have a DIV above the form, however, none of the testing is working. Please let me know if you need anymore information.

Is jQuery even loaded and working?

You can add an alert before the code to see if that section of code is even being run.

You can use the developer console to check if the form is being submitted with post data to the server.

You can check with the database to see if the submitted data is being saved properly.

If you do not have a test page for us to diagnose where the problem may be, this may be a long drawn out process as we help to teach you where and for what to check.

I apologize, I should’ve added more details. The form data is being inserted properly on my database, & all my server configuration has been verified by someone experienced. JQuery is being ran, I assume, in order to call AJAX functions.

The issue I’m having is regarding:

function(data){
            console.log(data);
            $("#response").html('<h3>Test Successful</h3>');
            alert('Test Success');


             var url = 'http://www.secursend.net'+ID;
            },

It should be replacing the DIV Response with a URL that directs the recipient to the data that was posted.

A couple of questions. What is the data that the server echo’s back to the that function, what do you expect that data should be, and where is that ID variable defined?

$("#response").html('<h3>Test Successful</h3>'); 

That line should be replacing the DIV Response located in my HTML. Nothings being populated, though. I’m not sure if there’s any conflicting code around it or why its not working properly.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.