• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Send requsts to a php file using AJAX

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a html file, which has a Javascript section:

<html>
<header>
<script src="my_util.js" language="javascript"></script>
...
</header>

<body scroll="no" >
<script language="JavaScript" type="text/javascript">
<!--

//Somewhere in the JS code, I need to call http://www.XYZ.com/php/my.php

// -->
</script>
...

</body>
</html>

I can not change the file extension from html to php. How should I do it?
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not savvy enough with the Apache web server (which is what I am assuming you are using to serve your php) to trick it into processing a file with a type .html instead of .php.
 
Elizabeth King
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it should belong to this forum.

I want to use Ajax to call the remote php file like following:

// I got XmlHttpRequest object successfully, but got an exception at the following line:
xmlHttpRequest.open('POST', "http://www.XYZ.com/php/my.php", true);

In FireFox, the exception was: Access to restricted URI denied code: "1012"

I also tried IE and Safari and got a similar error at the same line of the code.

I know I can call remote a Java object (servlet) in the same way, why not php?

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to be clear, "www.xyz.com" is the server where your page was served from, right? Otherwise this access is not allowed under the "same origin" rule.
 
Elizabeth King
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Just to be clear, "www.xyz.com" is the server where your page was served from, right? Otherwise this access is not allowed under the "same origin" rule.


Yes. Both the html and php are from www.xyz.com. I can access the www.xyz.com/php/my.php directly from a browser w/o problems.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, it was not clear that by "call" you meant an Ajax request. I've restored this to the HTML/JavaScript forum.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you specifying a port, both using www? Everything about the urls have to be the same [ no sub domains]

Eric
 
Elizabeth King
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Eric. It is the "www".
 
I can't take it! You are too smart for me! Here is the tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic