Jump to content

simple ajax question


ohdang888

Recommended Posts

say i have a page "mydomian.com/test.php"

and in that code, there is a line like this that has AJAX in it:

<script src="http://kyforobama.com/test.js" language="javascript" type="text/javascript"></script>

 

and the file it has in the ajax involves: Receive.php

 

would receive.php have to be on mydomain, or kyforobama?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/111606-simple-ajax-question/
Share on other sites

thats what i thought, but i'm getting some problems on this:

Theres no errors, but nothing comes up... i type in the box (on test.php) and nothing happens...

 

Go to http://kyforobama.com/test.js for the ajax that i'm calling

 

heres the code on my localhost test.php page:

<html>
<body>
<script src="http://kyforobama.com/test.js" language="javascript" type="text/javascript"></script>

<form name="myForm" method="POST">
Name: <input type="text"
onkeyup="ajaxFunction();" name="username" />
Time: <input type="text" name="time" />
</form>
<div id="testDIV"></div>
</body>
</html>

 

and on receive.php, all it has in it is this:

"this was from kyforobama.com"

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/111606-simple-ajax-question/#findComment-572891
Share on other sites

Well, a quick look at the js file and I saw one erro right off th ebat:

 

  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      document.getElementById('testDIV'). innerHTML = xmlHttp.responseText;
      }
    }

 

There is an errant space in the reference to the div object.

Link to comment
https://forums.phpfreaks.com/topic/111606-simple-ajax-question/#findComment-572941
Share on other sites

About Security

Apache Solution

 

Other solution:

Ajax call to YOUR server.  Your server's php file does a cURL or fopen or w/e to access the site instead, prints the same results you would want to gather off the remote site on your local page.  You get the same data, and handle accordingly.

 

The bypass is that your server opens the other server instead of making javascript do it which usually ends up with the security alerts.

Link to comment
https://forums.phpfreaks.com/topic/111606-simple-ajax-question/#findComment-573701
Share on other sites

A php page is executed on the server it's running on.  I was just saying that when you try to call a page that's not running on the same server as the page you're on, you usually get security warnings that stop you.  The work around is to have your ajax call a php page on your server, and have that page call the php page on the other server since php doesn't complain about getting data from remote servers.

Link to comment
https://forums.phpfreaks.com/topic/111606-simple-ajax-question/#findComment-573741
Share on other sites

i'm doing this as a learning project....

 

so i guess this could sum up my question... how do the ad networks do it??? They just javascript to call another javascript file on the ad servers and then display the ads from there(i think)... But you can't use javascript to query mysql stuff.. and some ad networks use php and mysql, so that's confusing me.

Link to comment
https://forums.phpfreaks.com/topic/111606-simple-ajax-question/#findComment-573830
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.