tags:

views:

92

answers:

3

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"&gt;
<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&amp;type=1&amp;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 ?

A: 

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

mjw06d
+2  A: 

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
A: 

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.

ferrari fan
That won't work because of browser security. Firefox, for example, won't let you make ajax requests to other domains. See @mjw06d
Dave Aaron Smith