Javascript AJAX read updated database changes without refresh

But I want to say “Your information has been saved”. because there are other fields that may have been changed. I really only need to update the username field and it doesn’t have to show in the popup.

That being said, how should I proceed?

Well, once we’ve got the URL updating, you can say whatever you fancy :slight_smile:

At the mo, the key is in making the server return the correct value (the username) for you to insert into the page.

I changed to that. The alert doesn’t popup as excepted and the username doesn’t change (unless refreshed). Am I missing something?

Have a look in the console. Which browser are you using?

I am using FF.

Only thing in the console is uner Error which looks like it has something to do with antivirus

Loading failed for the with source “https://ff.kis.v2.scr.kaspersky-labs.com/FD126C42-EBFA-4E12-B309-BB3FDD723AC1/main.js”. ListingUpdate.asp:5:1

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://ff.kis.v2.scr.kaspersky-labs.com/E3E8934C-235A-4B0E-825A-35A08381A191/abn/main.css. (Reason: CORS request did not succeed).

Hmm, weird, it should certainly log something to the console.

Try alerting it then:

if (xhr.status === 200) { alert(xhr.responseText); }

What do you see then?

I see that info has been saved but no show unless refresh

How are you returning a value from your ASP script to the client?

There must be a line towards the end of the ASP code that says echo("Your information has been saved"), or something similar

Yes, at the end of the page with ASP it’s:
response.Write (“Your information has been saved”)

But I don’t have any code that returns a value. Doesn’t it come back because of the save?

It’s that response.Write that is returning a value to the client.

Can you change it to return the username, so response.Write(userName) or whatever is applicable…

When I do that it brings back many lines of html on the form page and the url is not updated

Sounds like it’s returning the full HTML of an error Page.

What is the ASP code you are now using?

If this is what you mean: response.Write rs(“username”)

Don’t think you need those quotes, as username should be a variable.

Sorry, didn’t see the rs(“…”) bit.

Why do you need the rs bit, BTW?

Can you not just do: response.Write(username)

yes, with asp you need the " ". I tried without the quotes and still brings back lots of html

What does it bring back?

Just a lot of html on the form page, but doesn’t update the url

Yeah, so at this point you need to work out how to return a value from the ASP script and I’m afraid I can’t help you there.

Isn’t this where we got stuck previously?

Previously, we did this:

// Fetch content from database here
        var editorContent = '<%=rs("comments")%>';
        var editor = document.getElementById('editor-container');
        var hiddenInput = document.getElementById('myHtml');
        var form = document.forms.mainform;

The database was brought back with the rs(“comments”)

That’s on the client. What did the code on the server end up looking like?