javascript - Ajax not returning data -


hey trying return books beginning letter in case h. cant code work @ great full. html

<a href="" id="searchh" name="h" value="h"> <<<< clicked  <div id="ack2"></div> <<<<<< displayed here 

php

<?php include('db.php'); $letter = ""; $i = 0; $jsondata = '{"books":['; if(isset($_post['letter'])){     $letter = $_post['letter'];      $sqlstring = "select * book title '$letter%'";      $query = mysql_query($sqlstring) or die (mysql_error());      while ($row = mysql_fetch_array($query)) {         $i++;            $year = $row["year"];            $title = $row["title"];         $author = $row["author"];          $jsondata .= '{ "title":"'.$title.'", "author":"'.$author.'", "year":"'.$year.'" },';     }      $jsondata =  chop($jsondata, ",");     $jsondata .= ']}';     echo $jsondata; } ?> 

ajax/javascript

$("#searchh").click(function(){     letter = $("#searchh").val();     $.ajax({         type: "post",         url: "azlistscript.php",         data: "letter ="+letter,         success: function(html){             $("#ack2").html(html);             }             });     }); 

the php file return book data if change letter value manually displays books beginning h, need display in div tag on html page.

the value of click event logs no value in console

one problem can see is

letter = $("#searchh").val(); 

the element 'a' tag not form element .val() not work here. in stead try

letter = $("#searchh").attr('value'); 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -