i would need a script to be executed but the page

2019-12-16 20:22发布

问题:

i use the below code to navigate to a specific site via php code.

 header('Location:www.google.com'); 

i would need a script to be executed but the page shouldn't be navigated. my requirement is - i would like to send message to a person using a link but no page should be navigated as it by the click of a button - execution of the link at server end.

can you please let me know how to do.

thanks, Sam

回答1:

execute this code on a button click or a tag click event.

$.ajax({
    type: "POST",
    url: "sever url",
    data: { message: "hello" }
    })
    .done(function( msg ) {
    alert( "script executed successfully ");
    this.preventDefault(); // stops navigating from the page while <a> click or on submit click.
    });


标签: php url