我需要一个脚本来执行,但页面不应该被导航 [英] i would need a script to be executed but the page shouldn't be navigated

查看:31
本文介绍了我需要一个脚本来执行,但页面不应该被导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码通过 php 代码导航到特定站点.

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.

你能告诉我怎么做吗.

谢谢,山姆

推荐答案

在按钮单击或标签单击事件上执行此代码.

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.
    });

这篇关于我需要一个脚本来执行,但页面不应该被导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆