0

What now is:

A page on localhost, which sends a request:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <title></title>

<script language="javascript" type="text/javascript">
var script = document.createElement('script');

script.setAttribute('src', 'http://www.3dfind.ru/site/js.js');

document.getElementsByTagName('head')[0].appendChild(script);

</script>

 </head>

  <body>

<form method="get"> 
<div id='searchform'>
<table>
<td>
<input name='q' id='searchinput' type='text' value=''>
</td>
<td>
<select name='type' id='searchselect'>
<option value='1'>Val 1</option>
 </select>
</td>
<td>
  <input name='search' type='submit' onclick='MakeRequest();' value='Поиск!' id='searchsubmit'>
</td>
</table>
</form>

    <div id='ResponseDiv'>

    </div>
  </body>
</html>

Then there js script on the server, which receives the request:

function getXMLHttp()
{
  var xmlHttp

  try
  {
    //Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    //Internet Explorer
    try
    {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
      try
      {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e)
      {
        alert("Your browser does not support AJAX!")
        return false;
      }
    }
  }
  return xmlHttp;
}

function MakeRequest()
{
  var xmlHttp = getXMLHttp();


  var params = 'q=' + encodeURIComponent(q) + '&type=' + encodeURIComponent(type) + '&search=' + encodeURIComponent(s)
  xmlHttp.open("GET", '/result.php?'+params, true)
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      HandleResponse(xmlHttp.responseText);
    }
  }
  xmlHttp.send(null);

}

function HandleResponse(response)
{
  document.getElementById('ResponseDiv').innerHTML = response;
}

If the file result.php search on the server, you get a url:

http://3dfind.ru/site/result.php?q=%E4%F4%E4%E4%F4%E4&type=1&search=%CF%EE%E8%F1%EA%21

Also in result.php I accept the GET- request :

  $var = @$_GET['q'] ;
  $s = $_GET['s'] ;
  $typefile = $_GET['type'];

What am I doing wrong ?

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
Gena
  • 11
  • 1
  • 5
    I'm tempted to vote this up just because of the title. – pjmorse Sep 14 '10 at 16:29
  • 2
    What are you trying to ask here? What are you expecting to happen? Just posting all of your code is not helping anyone see the problem. – Jaime Garcia Sep 14 '10 at 16:31
  • @pjmorse I'm tempted to downvote it because it's hard to understand – Jaime Garcia Sep 14 '10 at 16:31
  • 1
    I am tempted to vote to close this just because of the title *I can not do cross-site request*. – Darin Dimitrov Sep 14 '10 at 16:32
  • 2
    @ferrari fan, I know it's not nice to pick on writing done by people for whom English isn't the first language (I would not do so well in Russian, or whichever Cyrillic-using language the original poster prefers) but "There is a long suffering" could be the preface to ever so many programming questions. – pjmorse Sep 14 '10 at 16:41
  • 1
    @pjmorse, I'm confused by the problem scope not by the language. And I completely agree with that the title of the question is a good one. – Jaime Garcia Sep 14 '10 at 16:46

3 Answers3

1

Alright my man, I think you're a bit confused. Your HTML contains

<input name='search' type='submit' onclick='MakeRequest();' value='Поиск!' id='searchsubmit'>

And your Javascript contains

function MakeRequest()

but you say "Then there js script on the server, which receives the request:"

The Javascript should be on the client and sends the request.

Then I'm not even sure what you're trying to do and what's going wrong. Are you getting errors? Is it supposed to do something that it isn't?

Back to basics: use Firefox and install Firebug. Enable the "console". Open your page and do what you're trying to do. If you have Javascript errors, they'll show in the console. You can open every ajax request in the console as well so you can see if you're getting a server side error.

Dave Aaron Smith
  • 4,517
  • 32
  • 37
0

Yeah, I'm a bit confused what you're asking, here is a reference you may look into for cross-site xmlhttprequests here. There is another good reference to cross-site requests here also

0

From your other question ("cross-site request") I think I understand what you're trying to do. I think you're trying to get the results from "results.php" which is hosted in a different server.

What you need to do is change your MakeRequest() function. Instead of

xmlHttp.open("GET", '/result.php?'+params, true)

it should be

xmlHttp.open("GET", 'http://URL_OF_OTHER_SERVER/result.php?'+params, true);

Hope this helps.

Community
  • 1
  • 1
Jaime Garcia
  • 6,744
  • 7
  • 49
  • 61