Sunday, 15 January 2012

Catch Ajax data variables in PHP? -


I am trying to get the data below to be captured in my alives.php page. Basically, alives.php requires a convertible $ passcode.

  & lt; Script & gt; $ {Document} .ready (function () {$ ('# alive'). Click (function () {var data = '& lt ;? php $ row [' code '] ;? & Gt; $$. AJX ({Type: "GET", cache: false, url: "alives.php", data: data, // Many data has been sent using Ajax success: function (html) {}}); Return false;});}); & Lt; / Script & gt;   

alives.php

  & lt; Php required ("database.php"); $ Checkvote = "Selection code of votes where code = '$ passcode'"; $ Updatealive = "Update votes SET live = +1 WHERE code = '$ passcode'"; $ Addvote = "Include votes (code, live) values ​​('$ passcode', + 1)"; $ Checkvoterlt = mysqli_query ($ conn, $ checkout); If (mysqli_num_rows ($ checkvoterlt)> 0) {$ result = mysqli_query ($ con, $ updatealive) or die (mysqli_error ()); } And {$ result = mysqli_query ($ con, $ addvote) or die (mysqli_error ()); } Mysqli_close ($ con); ? & Gt;    

is so wrong.

Issue 1: You specify a GET request: $. Ajax ({type: "GET", . If you want to post it:

  $. Ajax ({type: problem 2: your javascript data variable  key The value should be: Like  pair:  
  var data = {}   'passcode': code};   

Then get data in PHP with $ _ POST ['passcode']

No comments:

Post a Comment