0

Im using a mixture of php and javascript/jquery to scrape a websites prices from there webpage, there's no API so unfortunately I scrape the html page and pick up the prices/title from the html(I know this is a really risky way of doing it but its the only way).

Anyway, this is whats going on:

I pull in the external webpage using php file_get_contents()

This method is within a foreach loop, for every external page I want to grab data from.

This is my javascript.

<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js' type='text/javascript'></script>
            <script type='text/javascript'>
            console.log('page-{$i}');



                $('.page-{$i}').find('.search_result_row').each(function(i, obj) {
                    //This will give us each individual apps details. 
                    var appTitle    = $(this).find('.title').text();
                    var appPrice    = $(this).find('.search_price').text();
                    var appDiscount = $(this).find('.search_discount').text();

                    var appDetails = {
                        'appTitle'    : appTitle,
                        'appPrice'    : appPrice,
                    };

                    callAjax(appDetails);
                    var my_delay = 5000;

                    function callAjax(appDetails) {
                        $.ajax({
                         url: 'Upload.php',
                          type: 'POST',
                          data: appDetails,
                          dataType: 'JSON',
                         success:function(data) {
                                console.log(data);
                           },
                         error:function(jqXHR, textStatus, errorThrown) {
                            console.log('request failed ' + textStatus + errorThrown);

                            console.log(appDetails);
                         }
                        });
                    }
                });
            </script>

Everything works fine for the first URL, and for about half of the urls that I'm grabbing data from. The issue is SOME of the data being sent via ajax is returning the following error

Upload.php net::ERR_EMPTY_RESPONSE

Can any of you help?

TEster
  • 191
  • 2
  • 4
  • 19
  • this link may help you : http://stackoverflow.com/questions/6329462/getting-error-324-neterr-empty-response-when-using-memcache-in-kohana – Rahul Gopi Aug 13 '15 at 09:19

1 Answers1

0

Try this. You must stringify your details before you post them as json. This could be a reason for ERR_EMPTY_RESPONSE.

function callAjax(appDetails) {
                            appDetailsJsonString = JSON.stringify(appDetails);
                            $.ajax({
                             url: 'Upload.php',
                              type: 'POST',
                              data: {appDetailsJson: appDetailsJsonString},
                              dataType: 'json',
                             success:function(data) {
                                    console.log(data);
                               },
                             error:function(jqXHR, textStatus, errorThrown) {
                                console.log('request failed ' + textStatus + errorThrown);

                                console.log(appDetails);
                             }
                            });
                        }
  • If you implement the above function you should get a string in the parameter "appDetailsJson". This string would contain [{"appTitle":"some title", "appPrice":"someprice"}]. I don't know how you would operate in php. but this basically is what you get in a json string. Normally, in Java I would do a request.getParameter("appDetailsJson"); to get that string. – Achyuth Madhav Aug 13 '15 at 12:39