简体   繁体   English

通过jQuery Ajax发布并获取价值

[英]Post and Get value by jquery ajax

How can I add my values owdid and visited id after clicking below link by ajax? 单击ajax下面的链接后,如何添加我的值owdid和Visited ID?

<a href="index.php" onclick="insertvisit(<?php echo $interestid;?>)">member1</a>

Below is my insertvisit function. 以下是我的insertvisit函数。 I have defined owdid and interestid 我已经定义了owdid和interestid

function insertvisit(visitedid) {
  $.ajax({
       type: "POST",
       url: 'insertvisit.php',
       data:{'field1' : owdid, 'field2' : visitedid},
       success:function(html) {
       }
  });
}

and below is insertvisit.php 下面是insertvisit.php

global $pdo;
$ownid = $_GET['field1'];
$interestid =$_GET['field2'];

$query = $pdo->prepare("UPDATE tablem SET field1= ? WHERE field2= ?");
$query -> bindValue(1, $ownid);
$query -> bindValue(2, $interestid);
$query -> execute();

Please help thanks. 请帮忙谢谢。

You need to pass both value in function with , separated and also you need to change your function call like bellow 您需要在函数中使用,分隔传递两个值,还需要像下面这样更改函数调用

<a href="index.php" onclick="insertvisit(<?php echo $interestid.','.$owdid;?>)">member1</a>

And your function : 和你的功能:

function insertvisit(visitedid,owdid) {
   $.ajax({
           type: "POST",
           url: 'insertvisit.php',
           data:{'field1' : owdid, 'field2' : visitedid},
           success:function(html) {
           }
   });
}

and also you need to change your method $_GET to $_POST like below 并且您还需要将方法$ _GET更改为$ _POST,如下所示

$ownid = $_POST['field1'];
$interestid =$_POST['field2'];

$query = $pdo->prepare("UPDATE tablem SET field1= ? WHERE field2= ?");
$query -> bindValue(1, $ownid);
$query -> bindValue(2, $interestid);
$query -> execute();

i hope this will help you. 我希望这能帮到您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM