Jump to content
elcaiaimar

reload script from ajax

Recommended Posts

Hello, I'm trying to reload only a script instead of entire page. And I want to apply it in an ajax script. How could I do that?

 

My web contains a map(script of openlayers) and I put data into the map. So when I remove this data by a button I would like reload only the map.

 

Here is my code. It only shows an alert if the object has been removed or not:

// Autor: @jqcaper// Configuraciones Generalesvar nombre_tabla_pozos = "#tabla_pozos"; // idvar nombre_boton_eliminar_pozo = ".deletepozo"; // Clasevar nombre_formulario_modal_pozo = "#frmEliminarpozo"; //idvar nombre_ventana_modal_pozo = "#pozoModal"; // id// Fin de configuraciones$(document).on('ready',function(){    $(nombre_boton_eliminar_pozo).on('click',function(e){        e.preventDefault();        var Pid_pozo = $(this).attr('id');        var name_pozo = $(this).data('name');        $('#modal_idPozo').val(Pid_pozo);        $('#pozo_name').text(name_pozo);    });    var options_pozo = {        success:function(response)        {                        if(response.status=="True"){                alert("¡Object removed!");                var idPozo = response.pozo_id;                var elementospozo= $(nombre_tabla_pozos+' >tbody >tr').length;                if(elementospozo==1){                    location.reload();                }else{                    $('#tr'+idPozo).remove();                    $(nombre_ventana_modal_pozo).modal('hide');                }            }else{                alert("¡There was an error when remove!");                $(nombre_ventana_modal_pozo).modal('hide');                **RELOAD SCRIPT            };        }    };    $(nombre_formulario_modal_pozo).ajaxForm(options_pozo);});

Thank you very much!

 

 

Share this post


Link to post
Share on other sites

"Reload a script" doesn't make much sense. If you want to create the map the same way you did when you set the page up then just run the same code again after removing it.

Share this post


Link to post
Share on other sites

Ok, thanks for your clarification. Just a question, How could I run the script from my code? I've seen that you can do it with events but I dont want to use any button to do it.

 

Thank you again!

Share this post


Link to post
Share on other sites

I've seen that you can do it with events but I dont want to use any button to do it.

How do you want to do it then?

Share this post


Link to post
Share on other sites

Now, I click a button to remove db registers so I don't want to click another button to execute the map script. I think that the best way would be to click in the delete button, then shows an alert saying removed and automatically execute the script. For that, I've thought in execute it from the code above, if it was possible.

Share this post


Link to post
Share on other sites

If you want to run it on the same button click that's fine, there's no limit to how much code you can run at a certain time.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...