Editing page contents via Jquery and leaving fixed

Asked

Viewed 485 times

2

I would like to know the method of editing the page and leave the content I edited fixed there forever, as if it were a post.

I’ve tried that already:

<style type="text/css">
.aprovado{
    background-color: #060;
    color: #FFFFFF;
}
.reprovado{
    background-color: #f22;
    color: #E2E2E2;
}
</style>
    < script type="text/javascript" src="jquery-min.js"></script>
    < script type="text/javascript">
$(function(){

    $("#btn").click(function(){

        $("#resposta").removeClass();

        var nome = $("#txtnome").val();
        var n1 = parseFloat ($("#txtn1").val());
        var n2 = parseFloat ($("#txtn2").val());

        var media = (n1 + n2) / 2;           
        $("#resposta").html(nome + ", " + media);

        if(media >= 7){
            $("#resposta").addClass("aprovado");
        }else{
            $("#resposta").addClass("reprovado");
        }


    });

});
</script>
<h3>Ver Dados do Aluno</h3>
<form>
Nome: <input type="text" name="nome" id="txtnome" />
<br /><br />
Nota1: <input type="text" name="n1" id="txtn1" />
<br /><br />
Nota2: <input type="text" name="n2" id="txtn2" />
<br /><br />
<input type="button" value="Enviar Dados" id="btn" />
</form>
<div id="resposta"></div>

It works, more when updating the page some, but how do I save the changes only using AJAX and jQuery?

  • 2

    It’s unclear what you’re asking. Elaborate, or your question will probably be closed. What exactly is your problem? What have you tried?

  • Could someone really help, it’s urgent

  • 1

    Ajax serves to make client-server requests, when it changes the css class through a function, it runs only in the browser, and when you reload, it will go back to normal, which is programmed only in html. Find out the difference between running on the client side and on the server side. What you posted has nothing to do with ajax, only Jquery.

  • You want to set a change made by the user on the page or by you in the code?

  • By the user, it will be in the admin panel will have the option to edit contents of a page, it clicks on specified content, type the new text to be shown, and then gets fixed on the page.

  • You cannot do this only with javascript/jquery. You need a language running on the server, and possibly a database.

  • Database is no problem, more what kind of language do you mean? I currently know js,css,html,python and php.

  • Python and php serve. You need a webserver, which receives what has been modified and saves the result (on disk or in a comic).

  • Okay, very helpful, thank you.

Show 4 more comments

2 answers

2


Hello, from what I understand you are trying to edit an HTML content only with Javascript, but what you wanted to do is record an important data, such as a flag, saying that such student is approved or disapproved.

I’m sorry but you will need to use some resource to record this data, as a database, and to interact with it you will not be able to use only Javascript requiring the use of some other language like PHP, Ruby, etc.

Javascript acts only in the browser, this update you are doing is visible in the browser but no record is recorded anywhere to identify if the student is approved or not, if you want to perform the update in this way, works, but you will have to use another feature, like Ajax, which would send this information to another page, in PHP for example, and this would perform the update in your BD.

Good luck friend.

1

If you want to save the changes to be read later anywhere you link to your web page, you have to do what matheus_auler said. Already if you only need it in a browser and for a short period of time, can use HTML5 - Local Storage. With it you will save the data in the browser/browser and will not be able to access from elsewhere.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.