0

I am using following script.I am sending some data to php side using ajax and I need to find which all data I send to php have failed and I need to display failed data as html in client side.I am not getting how to find failed data and put all in html by using jquery.(I have 2 input box in html side and keep on adding data to server.Sometimes it may fail.I just want to find failed data and should allow to do ajax again to server) I find similar issues here JQuery: AJAX error: get data sent to server

<script type="text/javascript" language="javascript">
   $(document).ready(function() {
      $("#driver").click(function(event){
          $.ajax( {
             url:'/jquery/result',
data:{data1:a,data2:b},
             success:function(data) {
                $('#stage').html(data);
             }
          });
      });
   });
   </script>
Community
  • 1
  • 1
atc
  • 621
  • 8
  • 31
  • 1
    and where is the PHP script involved? and make sure that you have the correct `url: ` path – Kevin Nov 09 '14 at 09:19
  • I use php framework.I am getting success data back from php side and not getting an idea how to retrive every failed data and display in html – atc Nov 09 '14 at 09:20
  • sucess here means ajax query succeeded. failure means it is not able to connect to the file. Ajax failed. – Indra Kumar S Nov 09 '14 at 09:42
  • I am having similar problem http://stackoverflow.com/questions/23041632/jquery-ajax-error-get-data-sent-to-server – atc Nov 09 '14 at 12:05

1 Answers1

0

$.ajax has an error event which triggers if the ajax call can't access the url property (404, 500 errors).

In case you want to verify if the custom data you send to the url fails then you will need some code in your PHP script and success event.

eg: let's say you expect data1 to be an integer. In php

if(!is_int($_POST['data1])) echo 'Fail'.

In success event you will verify if(data == 'Fail') /** display error code goes here**/

CGeorges
  • 488
  • 4
  • 16
  • I understand $.ajax has an error event .Let's say I am sending a data to server.(for eg: data1="hello").Does it possible to catch this data if ajax fails ?I am just trying I have sent "hello" to server.But that data failed and returning the text to user – atc Nov 09 '14 at 11:51
  • @aniltc When you look in the network tab of your browser, how does your ajax call fail ? status code 404, 500 or is it not failing (202) ? – CGeorges Nov 09 '14 at 12:15
  • its 404 & 500.Some times my data is not saving from php to database – atc Nov 09 '14 at 12:22
  • I am having similar problem http://stackoverflow.com/questions/23041632/jquery-ajax-error-get-data-sent-to-server – atc Nov 09 '14 at 12:29