php - AJAX Request fails because of file_get_contents -




i'm doing fun project myself, involves getting html source web (from different domain) , getting info of it.

in first steps made in php worked fine, i'm trying make better jquery page works dynamically.

the thing ajax request fails whenever reaches "file_get_contents" call (which 1 gives me html source of url).

the js part:

$.ajax({             type: 'get',             url: 'getimage.php',             data: {referencia: $("#referencia").val()},             success: function(data){                 var div = document.getelementbyid("print");                 alert(data);                 div.innerhtml = "<img src="+""+"/>"; //not finished              },             error: function() {                 alert("error");             } }); 

the server part:

<?php     $ref = $_post['referencia'];      if(isset($_get['referencia'])){         $url = /*some external url concatened post data*/;          $data = file_get_contents($url);          echo $data;     } ?> 

some notes can provide: -changing type of ajax post make fail, if remove "file_get_contents" line. -i tried kind of request no luck (this 1 doesn't fails when reaching "file_get_contents" line when executing function, doesn't return anything, have tested standalone without requests , works fine):

    var req = new xmlhttprequest();      req.open("post", "getimage.php", true);      req.setrequestheader("content-type", "application/x-www-form-urlencoded")     req.onreadystatechange = function(){         if(req.readystate == 4 && req.status == 200){             var div = document.getelementbyid("print");             alert(req.responsetext);             div.innerhtml = "<img src="+""+"/>";         }     }      req.send("referencia=" + encodeuricomponent($("#referencia").val())); 





wiki

Comments

Popular posts from this blog

elasticsearch - what is the equivalent data type for geo_point in hibernate search? -

Jenkins: find build number for git commit -

firebase - How to wait value in Ionic 2 -