O
O
Otrivin2015-09-08 22:05:57
PHP
Otrivin, 2015-09-08 22:05:57

How to get results of ajax request from third party site using jsonp?

Hello!
On a third-party site, there is a form in which certain types of data are entered. The server receives them, processes them, and then issues the result. The design on this third party site is as follows:

<div class="panel-body">
    <form role="form">
      <label for="vin">VIN:</label> 				
      <input type="text" class="form-control" id="vin" placeholder="VIN" />

      <label for="regNumber">Гос.номер:</label> 				
      <input type="text" class="form-control" id="regNumber" placeholder="Гос.номер" /> 		

      <label for="BodyNumber">Номер кузова:</label>
      <input type="text" class="form-control" id="BodyNumber" placeholder="Номер кузова" /> 	

      <label for="FrameNumber">Номер рамы:</label>
      <input type="text" class="form-control" id="FrameNumber" placeholder="Номер рамы" /> 		
    </form> 
    <p></p>
    <div id="resultEAISTO"></div>
    <p></p>
    <button type="button" onclick="eaisto();" class="btn btn-block btn-primary ">Проверить</button>
  </div>

  <script type="text/javascript">
    function eaisto()
    {
    var vin = $('#vin').val();
    var regNumber = $('#regNumber').val();
    var BodyNumber = $('#BodyNumber').val();
    var FrameNumber = $('#FrameNumber').val(); 
         $.ajax({
            type: "POST",
            url: "./services/poiskEAISTO.php",
            data: "vin="+vin+"&regNumber="+regNumber+"&BodyNumber="+BodyNumber+"&FrameNumber="+FrameNumber,
            // Выводим то что вернул PHP
            success: function(html) {
                $("#resultEAISTO").empty();
                $("#resultEAISTO").append(html);
            }
        });

    }
  </script>


Tell me, please, how can I access this form, submit data, get the result and display it on my own? I tried to do it through jsonp (as I understand it, this is the least thorny path), I created an html page for the test with the following code:

<html>
  <head>
  <meta charset="utf-8">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
  </head>
  <body>
    <div class="panel-body">
      <form role="form">
        <label for="vin">VIN:</label> 				
        <input type="text" class="form-control" id="vin" placeholder="VIN" />

        <label for="regNumber">Гос.номер:</label> 				
        <input type="text" class="form-control" id="regNumber" placeholder="Гос.номер" /> 		
                   
        <label for="BodyNumber">Номер кузова:</label>
        <input type="text" class="form-control" id="BodyNumber" placeholder="Номер кузова" /> 	
                   
        <label for="FrameNumber">Номер рамы:</label>
        <input type="text" class="form-control" id="FrameNumber" placeholder="Номер рамы" /> 		
      </form> 
      <p></p>
      <div id="resultEAISTO"></div>
      <p></p>
      <button type="button" onclick="eaisto();" class="btn btn-block btn-primary ">Проверить</button>
    </div>

    <script type="text/javascript">
      function eaisto()
      {
      var vin = $('#vin').val();
      var regNumber = $('#regNumber').val();
      var BodyNumber = $('#BodyNumber').val();
      var FrameNumber = $('#FrameNumber').val(); 
           $.ajax({
              type: "POST",
              url: "http://web-dk.ru/services/poiskEAISTO.php?callback=?",
              data: "vin="+vin+"&regNumber="+regNumber+"&BodyNumber="+BodyNumber+"&FrameNumber="+FrameNumber,
              dataType: "jsonp",
              // Выводим то что вернул PHP
              success: function(html) {
                  $("#resultEAISTO").empty();
                  $("#resultEAISTO").append(html);
                  alert( "Отладка, прибыли данные: " + html );
              },
              error: function() {
                  alert( "Беда, эггог" );
              }
          });
      }
    </script>
  </body>
</html>


After entering the VIN and pressing the "check" button, an error message pops up (embedded in error), and in the browser console I see a message indicating
SyntaxError: expected expression, got '<'
http://web-dk.ru/services/poiskEAISTO.php?callback=jQuery111209190400557866112_1441734625394&vin=здесь VIN, который мы вводили&regNumber=здесь гос.номер&BodyNumber=номер кузова&FrameNumber=номер рамы&_=1441734625396
When I click on the link, I see the following code in cp1251 encoding:

<div class="alert alert-success">ааЕ аЗаАаПаОаЛаНаЕаНаО аНаИ аОаДаНаОаГаО аПаАбаАаМаЕббаА</div>


If you translate it into utf-8, then it will take a readable form:

<div class="alert alert-success">Не заполнено ни одного параметра</div>


What's the matter? Parameters not being passed? How to make the code work?

Z.Y. Don't kick me, I'm more of a coder than a programmer.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kovalsky, 2015-09-08
@dmitryKovalskiy

Are you 100% sure that the site does not use CSRF protection?

M
Maxim, 2015-09-08
@maxloyko

If I'm not mistaken it's not possible to make a jsonp POST request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question