Tuesday 15 June 2010

javascript - Ajax JQuery success function not working -



javascript - Ajax JQuery success function not working -

i'm not sure has gone wrong, reason success function in ajax isn't calling function. i'm asking phone call after php completed.

for php have $test = 'hi'; echo json_encode($test);

here code main page:

<?php session_start(); if(!isset($_session["b2_in"])){ header("location: b2.php"); } ?> <script> $(document).ready(function(){ $("form input:submit").click(function() { $.ajax({ type: "post", url: 'b2_send.php', data: $('form').serialize(), datatype: 'json', //beforesend: function(){ $("#send").val('sending...');}, success: function(data) { testfunction(); }, statuscode: { 403: function(e) { $("say").highlight(); $("#message").html(e.responsetext); } } }); homecoming false; }); }); function testfunction(){ $("#message").val(""); } </script> <say> <form> <input type="text" name="message" class="message" id="message"/> <input type="submit" name="send" value='say' id="send"/> <span id="message" style="font-weight:bold;color:red;"></span> </form> </say>

try

span block element of dom , hence set info it, need utilize $(id).html(data); , not val()

also should have different id each elemnt in dom, pick first id gets in dom, , in case is

<input type="text" name="message" class="message" id="message"/> alter value of element

<script> $(document).ready(function(){ $("form input:submit").click(function() { $.ajax({ type: "post", url: 'b2_send.php', data: $('form').serialize(), datatype: 'json', //beforesend: function(){ $("#send").val('sending...');}, success: function(data) { testfunction(); }, statuscode: { 403: function(e) { $("say").highlight(); $("#message").html(e.responsetext); } } }); homecoming false; }); }); function testfunction(){ $("#message").html(""); } </script>

javascript php jquery ajax

No comments:

Post a Comment