jQuery 简单的 php ajax 请求 url

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15780031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 15:47:16  来源:igfitidea点击:

simple php ajax request url

jqueryajax

提问by user2234992

I have many links like this... different link id me for different items

我有很多这样的链接...不同的链接标识我不同的项目

<a class="member" href="http//ex.com/action.php?me=1">link1</a>

so when I click this I want to navigate to action.phpfrom here (here.php) I am using ajax to do this.

所以当我点击这个我想action.php从这里导航到( here.php) 我使用 ajax 来做到这一点。

I'm new to jQuery.. I am not able to understand the usage the urlparameter.. I tried many posts found here... wanted to the basic way to send the --me-- value from here.phpto action.php..

我是新来的jQuery ..我无法理解使用的url参数。我试图找到很多帖子在这里...想从发送--me--价值的基本途径here.php,以action.php..

$("a.member").click(function(e) {
    $.ajax({
        type: "GET",
        url: "action.php?",
        data: "me=" + me,
        success: function (data) {
            alert(data);
        }
    });

    return false;

    e.preventDefault();
});

回答by Roger

Here is an example,

这是一个例子,

The jquery part:

jquery部分:

$("#update").click(function(e) {
    e.preventDefault();
    var name = 'roger'; 
    var last_name = 'blake';
    var dataString = 'name='+name+'&last_name='+last_name;

    $.ajax({
        type:'POST',
        data:dataString,
        url:'insert.php',
        success:function(data) {
            alert(data);
        }
    });
});

The insert.phppage

insert.php

<?php
    $name = $_POST['name'];
    $last_name = $_POST['last_name'];
    $insert = "insert into TABLE_NAME values('$name','$last_name')";// Do Your Insert Query
    if(mysql_query($insert)) {
        echo "Success";
    } else {
        echo "Cannot Insert";
    }
?>

Note: do not use mysql_* functions

注意:不要使用 mysql_* 函数

Hope this helps,

希望这可以帮助,

回答by Gaurav

Try this :

尝试这个 :

$.ajax({
    type: "GET",
    url: "action.php",
    data: {
        me: me
    },
    success: function (data) {
        alert(data);

    }
});

回答by Musa

Since the parameter is already in the <a>'s href url just pass that to url

由于参数已经在<a>'s href url 中,只需将其传递给 url

$("a.member").click(function(e){ 
     $.ajax({
            type: "GET",
            url: this.href,
            success: function(data){
                      alert(data);
            }
     });
     return false;
});