0

I'm having trouble understanding what I'm missing or not doing here (obviously something), and maybe someone can help.

I have a database site that displays a table generated from a SQL database on the client side. When the table is initialized, this code is executed and pulls the data needed for the dropdown in question (comments added by me for this post):

$selectOwner = "SELECT DISTINCT [Contacts].[Alias], [Contacts].[Last Name], [Contacts].[ID] FROM [TechInv].[dbo].[Contacts]";

//this is the file that contains the above query variable
require('custom/Connection.php');

$owner_arr = array();

//$conn is our connection string
$response = sqlsrv_query($conn, $selectOwner);
while ($row = sqlsrv_fetch_array($response)){
    array_push($owner_arr, $row['Alias'] . " " . $row['Last Name']);
}

This generates a list of name records pulled from the database in a Alias(first name) Last Name format.

Here's where I'm having trouble

Another function of the site is a menu that allows users of a certain priveledge level to add additional contacts to the table. Everything works fine with that except nowhere in the code is the above array updated when a contact is added, which forces the user to reload the page, ew.

I know i need to use $.ajax for this, so I took a stab at it, and put the following code into the click handler for the 'add contact' submit button:

$.ajax({
    type: 'POST',
    data: 'listRefresh();',
    url: 'wp-content/plugins/editable-grids-api-liam/regenOwnerArr.php',
    success: function() {
        alert("this succeeded?");
    }
});

The data: 'listRefresh();' line refers to a function I created that is the same as the first block of code, in an attempt to just refresh the variables with new data. That's obviously where I've gone wrong, (try not to laugh) but I am out of ideas here. Can anyone shed some light?

1 Answer 1

3

Your ajax call is wrong. The 'data' value is what you send to the server.

Try this:

$.ajax({ 
    type: 'POST', 
    url: 'wp-content/plugins/editable-grids-api-liam/regenOwnerArr.php', 
    success: function(data) {
        listRefresh(data);
        alert("this succeeded?"); 
    } 
});

The data variable is what the server gives you back, so you can pass that data to the listRefresh() function and re-render the upated list.

In alternative, you could just reload the page putting location.reload(); into success function

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I honestly didn't think that passing a function call would work at all, but that is viable :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.