i making ajax call .php page making query database. however, when echo value .php page, entire html file returned rather numerical value need.
this ajax script:
<script type="text/javascript"> $(document).ready(function() { $("#valuebutton").click(function() { var id1=$('.player1').val(); $.ajax ({ type: "post", url: "updatevaluebox.php", data: ({g1: id1}), cache: false, success: function(value) { //alert(value); $('#valuebox').val(value); } }); }); }); </script> and php page updatevaluebox.php:
<?php require("connect_db.php"); $q="select price playerlist id=".$_post['g1']; $r=mysqli_query($dbc,$q); $price=mysqli_fetch_array($r,mysqli_num); mysqli_close($dbc); echo $price[0]; ?> both files in same directory.
i have checked other answers question on stackoverflow none seem work.
the output getting alert statement looks like:
<html> <head><title> </title></head> <body> </body> </html>5.5 the 5.5 @ end value need!
i have set ajax datatype text doesn't help.
yep! need remove html in connect_db.php file. recommend storing variable in file checking if connection successful. example:
connect_db.php
$isconnected = false; $dberror = ""; if ($dbc=mysqli_connect('localhost','*****','*****','ff') { $isconnected = true; } else { $dberror = mysqli_connect_error(); } other files
require("connect_db.php"); if($isconnected) { //do yo stuff!! } else { //handle error like, printing out echo $dberror; } doing allow handle db logic in files if fails connect may handle failed connections gracefully.
Comments
Post a Comment