php - jquery ajax results message -


i have ajax call php script updates mysql db new record when user submits data string entry. part of php if/else in place check see if entry duplicate. can stop duplicate updating database don't know how send "error" message says "that record exists"...here jquery: [script] $(function() {

    $(".entry_button").click(function()  {     var element = $(this);     var boxval = $("#entry").val();     var datastring = 'entry='+ boxval;         if(boxval=='') {             alert("please enter text");         } else {              $("#flash").show();             $("#flash").fadein(400).html('<img src="images/loading.gif" align="absmiddle">&nbsp;<span class="loading">broifying it...</span>');             $.ajax({                     type: "post",                     url: "update_data.php",                     data: datastring,                     cache: false,                     success: function(html){                         $("ol#update").prepend(html);                         $("ol#update li").slidedown("slow");                         document.getelementbyid('entry').value='';                         $("#flash").hide();                     }              });         }         return false;     }); }); [/script] 

and here php script updates db (update_data.php):

[php] include('db.php'); if(isset($_post['entry'])) { $date_created = date('y-m-d h:i:s'); $entry = $_post['entry']; $query = "select count(*) count table entry = '$entry'"; $result = mysql_query($query); $row = mysql_fetch_array($result); if ($row['count'] == 0) { mysql_query("insert table (entry,date_created) values     ('$entry','$date_created')"); $sql_in= mysql_query("select entry,id table order id desc"); $r=mysql_fetch_array($sql_in); $newentry=$r['newentry']; $id=$r['id']; ?> <li class="entry bar<?php echo $id; ?>"> <div class="thebro"><span><?php echo $newentry; ?></span></div> <div class="hr"></div> <div class="utility-left"><span class="share"><a href="#" title="share">share</a></span> | <span class="time">days ago</span></div> <div class="utility-right"><span class="comments">comments</span> | <span  class="like">like</span></div> </li> <?php } else { $error = "sorry, record exists"; }     } [/php] 

i want able spit $error variable php script sent in ajax call , displayed in element in html. i've googled crap out of ajax error messages have header errors, not validation error messages. not using json_encode, unless wants redo jquery chunk above sent json data.

any ideas awesome!

just echo in phpfile , use:

document.getelementbyid('ajaxcatchbox').innerhtml = ajaxrequest.responsetext; 

the responsetext ajaxrequest object picks thats echoed... dunno equivalent in jquery tho


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -