0

i have a problem, help please

i have 2 sites and i want send data each other

first site :

          var site_adres = $(location).attr('href');

          var myArray = site_adres.split('/');

          var site_adi_al = myArray[2];

          $.getJSON('xxx.com/site/admin.php?site_adres='+ site_adi_al +'',  

            {},
        function (data) {  

         $.each( data, function ( i, val ) {

         var id=val['id'];
         var site_adi=val['site_adi'];
         $(".site_adi").append('<li>'+id+' >> <a href="'+site_adi+'"   
         target="_blank">'+site_adi+'</a></li>');



          });

second site:

                     $site_adi = $_GET["site_adi"];

/* query */

              $query = mysql_query("SELECT * FROM site WHERE site_adi = '$site_adi'");
            if ( mysql_affected_rows() ){
              $row = mysql_fetch_object($query);
              $json = array(
              "id" => $row->id,
              "site_adi" => $row->site_adi
                  );
             }else{
              $json["hata"] = "Nothing !";
                 }
          header("access-control-allow-origin: *");
          echo json_encode($json);

result zero, what is wrong, help please

  • **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Aug 19 '14 at 13:46
  • What have you done to debug this? Open your browser's developer tools. Look at the JavaScript error console. Are there any errors? What about the Net tab? Do you see the request being made? Do you get the response you expect? – Quentin Aug 19 '14 at 13:47
  • console error empty, network tab: jquery.min.map code.jquery.com not found?? oppps why. include that page – mizikcicocuk Aug 19 '14 at 14:05
  • What does the Net tab say about the request to `xxx.com/site/admin.php?site_adres=`? – Quentin Aug 19 '14 at 14:13
  • i noticed. solition?? site/admin.php?site_adres=http://mizikci.byethost14.com/ result: nothing – mizikcicocuk Aug 19 '14 at 14:22
  • "nothing"? Define "nothing"? Does it timeout? Does it give a `200 OK` response with no content? – Quentin Aug 19 '14 at 14:26
  • {"id":null,"site_adi":null} – mizikcicocuk Aug 19 '14 at 14:33
  • What is that? Is that the response from the PHP? So it isn't an array, but you are trying to treat it as one. that's your problem. – Quentin Aug 19 '14 at 14:36

2 Answers2

0

You have two basic problems (aside from the security issues explained in the comments on the question).

  1. You are sending site_adres but reading $_GET["site_adi"]. You can't use different names for the same thing without explicitly writing code to link them somehow.
  2. You are looping over data with $.each( data, function ( i, val ) { as if it was an array of objects, but your PHP is only sending a single object (which isn't in an array). You should be accessing the properties of data directly and not using each or val.
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
-1

You should set up CORS on your webservers to allow them to fetch data from each other, since you're using php, i'm gonna assume you're using apache:

Header set Access-Control-Allow-Origin "*" 

replace the * with the ip adress of your other website and vice versa.

Brunis
  • 1,073
  • 8
  • 12