|
|
#1 (permalink) |
|
Registered User
Fresh Surpasser
Joined in Aug 2004
Lives in Poland
Hosted on pass7
21 posts
Gave thanks: 0
Thanked 0 times
|
Ajax problem (forbidden)
Hi.
I have a problem with Ajax. All my remote methods returns 403 code (request forbidden). Ajax app is very simple and it works on local server. I tested my ajax app with JPSpan and HTML_AJAX (from Pear) implementation. Is it Apache config specific? Should I set some vars in .htaccess? Please help.
__________________
Jacek Czapla<br/> pass60 |
|
|
|
|
|
#2 (permalink) |
|
All Ur Base R Belong 2 Us
Excelling Contributor
Joined in Feb 2005
Lives in Vegas & New York
824 posts
Gave thanks: 2
Thanked 6 times
|
From what I understand, you generally can't use a XMLHTTPRequest for remote files, the requests need to be on local files.
I'm probably what you could call something of an Ajax Dummy (i've only read about it and read through examples, haven't tried myself yet) Share some of the code without any "sensitive" information for the script. I can generally help debug even if I can't program it myself ![]()
__________________
Nobody doing nothing |
|
|
|
|
|
#3 (permalink) |
|
Registered User
Fresh Surpasser
Joined in Aug 2004
Lives in Poland
Hosted on pass7
21 posts
Gave thanks: 0
Thanked 0 times
|
Thanks for reply.
An example: There are 3 files on server: server.php Code:
<?php
session_start();
require_once 'JPSpan.php';
require_once JPSPAN.'Server/PostOffice.php';
require_once('class.php');
$S= & new JPSpan_Server_PostOffice();
$S->addHandler(new klasa());
if(isset($_SERVER['QUERY_STRING']) && strcasecmp($_SERVER['QUERY_STRING'], 'client')==0){
$S->displayClient();
}else{
$S->serve();
}
?>
$S->displayClient(); - this method returns js script for browser with classes.methods for communication, data serialisation etc. $S->serve(); - ajax requests processing buissines logic class - class.php Code:
<?php
session_start();
class klasa{
function k_write($word){
$data=$_SESSION['data'];
array_push($data, $word);
$_SESSION['data']=$data;
return $data;
}
function k_read(){
$data=array('1', '2', '3');
if(isset($_SESSION['data']))
$data=$_SESSION['data'];
return $data;
}
}
?>
another file client.html (it can be viewed from http://demo.taksowka.net/dev/client.html) In this file there are js methods, input field, div section for data displaing etc. There is body onLoad function and after page loading we can see error message (403 forbidden). The message is generated by JPSpan class from XMLHTTPRequest status value (IMHO).
__________________
Jacek Czapla<br/> pass60 |
|
|
|
|
|
#4 (permalink) |
|
All Ur Base R Belong 2 Us
Excelling Contributor
Joined in Feb 2005
Lives in Vegas & New York
824 posts
Gave thanks: 2
Thanked 6 times
|
When I go directly to this url http://demo.taksowka.net/dev/server.php
Without a query string, I get the following: Fatal error: Invalid HTTP request method: GET in /home2/etaxi/public_html/demo/dev/JPSpan/Server/PostOffice.php on line 72
__________________
Nobody doing nothing |
|
|
|
|
|
#5 (permalink) |
|
Registered User
Fresh Surpasser
Joined in Aug 2004
Lives in Poland
Hosted on pass7
21 posts
Gave thanks: 0
Thanked 0 times
|
OK. Thanks. But I think it is not my problem because I use url like this
http://demo.taksowka.net/dev/server.php?client with ?client at the end and this url correctly returns javascript client code for AJAX operations based on my buissnes logic class (class.php). The same error (403 forbidden) I got with other PHP- AJAX library (HTML_AJAX).
__________________
Jacek Czapla<br/> pass60 |
|
|
|
|
|
#6 (permalink) | |
|
Registered User
Seasoned Poster
Joined in Jun 2004
Lives in Warsaw, Poland
Hosted on saprus
69 posts
Gave thanks: 0
Thanked 1 Time in 1 Post
|
I have problems understanding where exactly problem occurs.
What do you mean with: Quote:
Do methods return 403 code (?!) or you get this error when you try to access file where this methods are placed? |
|
|
|
|
|
|
#7 (permalink) |
|
Registered User
Fresh Surpasser
Joined in Aug 2004
Lives in Poland
Hosted on pass7
21 posts
Gave thanks: 0
Thanked 0 times
|
Remote method (here) is php function (php class method) which is called by javascript function by XMLHTTPRequest. Local method is javascript function called in browser. Url called by xmlhttprequest looks like this:
http://domain.name.com/server.php?ph...s_method_name/ In php-ajax librarys like JPSpan or HTML_AJAX there is php server class and this class generates javascript client code (on special request in <script> tag) for calling (registered in server class) php functions by XMLHTTPRequest (similarly to XML-RPC). php server and generated javascript code can have many features built in (objects and arrays serialisation, exeption handling) In my code on pass7 server every call of php method by javascript function returns 403 error. I posted example code in previous messages. Latest news: I checked this again few minutes ago, and now it works. That's strange. Thanks for spiritually help :-)
__________________
Jacek Czapla<br/> pass60 Last edited by Jacek Czapla; February 13th, 2006 at 5:00 PM. |
|
|
|
|
|
#8 (permalink) |
|
Registered User
Seasoned Poster
Joined in Jun 2004
Lives in Warsaw, Poland
Hosted on saprus
69 posts
Gave thanks: 0
Thanked 1 Time in 1 Post
|
xmlHttp object is incapable to call any php method directly.
What it can do is send request to server and receive response as http document. I understand then.. that url (which has some request data) that your xmlHttp object is calling should force php to invoke some php methods on server. And problem is that calling that url with xmlHttp object returns 403 error (so php script is not called at all) That's how I understand what's happening behind your classes. 403 error is I think privileges issues like browser is not allowed to execute script on server - that looks totally strange to me.. as if browser is forbiden to do so then you shouldn't be able to access that url from address bar as well. Make sure what really is going on behind the scene.. what url is invoked? Do you get same error (403) when you try to access url from address bar? Probably just changing access privileges on files that url points to should solve issue. |
|
|
|
|
|
#9 (permalink) | |||
|
Registered User
Fresh Surpasser
Joined in Aug 2004
Lives in Poland
Hosted on pass7
21 posts
Gave thanks: 0
Thanked 0 times
|
Quote:
Quote:
URL is http://demo.taksowka.net/dev/server.php?klasa/k_read but it have to be sended by post method. Quote:
I'm pretty sure that is not code bug and like I wrote before now it works fine so I leave this out. Thanks for interesting. PS. English knowledge checking. Do you realy understand what am I writing? ![]()
__________________
Jacek Czapla<br/> pass60 |
|||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|