0

I'm trying to show a div which contains a texbox and a button, in my web page.

the div is not in my server, is a third party web and I don't have access to modify the base code.

this is posible??? this is the code that I want to display in my web, from the third party web.

the div tag id is "body"

<div id="body"> 
        <h2>Consulta de Teléfonos Robados o Bloqueados por IMEI</h2><div style="width:100%; height:auto;">
<script type="text/javascript">
function buscar(keyWords){
jQuery(document).ready(function($){
    $.post('../../../bdtronline/sistema/areas.php',{
    accion:'searchImei',
    keyWords:keyWords},
    function(data){$('#listImeiFound').html(data);});
});
}
</script>
<form>
Buscar <input type="text" id="keyWords" name="keyWords" size="50" /><input type="button" value="buscar" onclick="buscar(document.getElementById('keyWords').value);"     />
</form>
</body>
a2j
  • 33
  • 7
  • Take a look at [this answer](http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain#answer-3506238). – Matteo B. Jul 18 '14 at 16:32
  • You cannot directly request some html element from a remote server, but an html document. From that you can extract the desired element. But usually there is a better solution, since this is highly error prone. – arkascha Jul 18 '14 at 16:35
  • Do you have PHP running on your server (on the same domain your JavaScript runs at)? – Matteo B. Jul 18 '14 at 16:38
  • Thanks! but I have no access to the second page, I can't modify it, thats why I just want to show the div in my web – a2j Jul 18 '14 at 16:39
  • Matmarbon, I have php in my server, but is not the same server from the third party. – a2j Jul 18 '14 at 16:41
  • arkascha, pleease tell me how I can do that! I can use that – a2j Jul 18 '14 at 16:48

1 Answers1

0

If you have PHP running on the server your JavaScript runs at, you can load a page of your server, that takes the page content from the other domain via PHP:

proxy.php:

<?php
$opts = array('http' =>
  array(
    'method'  => 'POST',
    'header'  => "Content-Type: application/x-www-form-urlencoded",
    'content' => http_build_query($_POST)
  )
);
$context = stream_context_create($opts);
echo file_get_contents('http://php.net/manual/en/function.file-get-contents.php', false, $context);

yoursite.html

// ...
jQuery(document).ready(function($){
    $.post('proxy.php',{
      accion:'searchImei',
      keyWords:keyWords},
      function(data){$('#listImeiFound').html(data);});
    });
});
// ...
Matteo B.
  • 3,906
  • 2
  • 29
  • 43
  • @a2j If it worked, please mark it as correct. If not, there will probably follow more/better answers. If you lost your interest or did something else to get it working, then edit that information into your question so everybody knows what is going on! – Matteo B. Jul 21 '14 at 07:32
  • ok, did not work, this code show the web, but when I fill it and click submit does nothing :-( – a2j Jul 22 '14 at 19:49
  • @a2j Let me try to understand, what you say. Does `this code show the web` mean `this code is shown in the browser` or `this code shows a website`? If it means the first, just add another line into the file at the beginning ` – Matteo B. Jul 23 '14 at 07:38
  • sorry my bad, The code in proxy.php works fine, and shows the third party website. But inside of the third party website there is a form, when I fill that form and press the button to send the info, the form does nothing, I want fill that form and show the answer. – a2j Jul 24 '14 at 00:30