ajax: permission denied error
Posted: Wed Jul 18, 2007 10:56 am
i have a very simple page, ajaxTest.php which has a form to insert a scrap. it includes two files, core.js and scrap.js. the form sends poster and message values to insertScrap method in scrap.js and scrap.js makes an appropriate POST request to a core method sndReq() in core.js. The core.js actually send the POST request to a PHP file, PW_C_Scrap.js and it will process it and return text.
but i have been getting the following message when xmlhttp opens a POST request, 'Error: uncaught exception: Permission denied to call method XMLHttpRequest.open';
core.js
ajaxTest.php
PW_C_Scrap.php
but i have been getting the following message when xmlhttp opens a POST request, 'Error: uncaught exception: Permission denied to call method XMLHttpRequest.open';
core.js
Code: Select all
var http = createRequestObject();
//create xmlHTTP obj
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
function sndReq(sendMethod, url, event, parameters) {
alert( 'sendMethod: ' + sendMethod + ' url: ' + url + ' event: ' + event );
//informToWait( 'AJAX Message: Please wait until content loads ...' );
http.open( sendMethod, url, true );
if( sendMethod == 'post' ){
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", parameters.length);
http.setRequestHeader("Connection", "close");
http.send(parameters);
}
http.onreadystatechange = function(){
alert( 'http state: ' + http.readyState + 'event: ' + event );
if(http.readyState==4){
if( event == 'insertScrap' ){
document.getElementById( 'scrapContent' ).innerHTML = http.responseText;
}
}
}
http.send(null);
}
[/script]
scrap.js
[script]
function insertScrap( poster, msg ){
alert( poster + '-' + msg );
var parameters = 'poster=' + encodeURI( poster ) + '&msg=' + encodeURI( msg );
alert( parameters );
sndReq( 'post', 'http://www.thisisraghavan.com/home/controllers/PW_C_Scrap.php?action=insert', 'insertScrap', parameters );
}
function informToWait( input ){
document.getElementById( 'output' ).innerHTML = input;
}
[/script]
Code: Select all
<script src="views/javascript/core.js"></script>
<script src="views/javascript/scrap.js"></script>
<div>
<div style = "font-weight:bold; padding:4px">Scrap Book</div>
<div style = "border:1px solid black; width:200px;"></div>
<div id = 'insertScrapForm'>
<form>
<table>
<tr>
<th>Name</th><td><input type='text' name = 'poster' value = '' /></td>
<th>Message</th><td><input type='text' name = 'msg' value = '' /></td>
<th></th><td><input type="button" onclick="insertScrap( this.form.poster.value, this.form.msg.value )" value="Post Scrap" /></td>
</tr>
</table>
</form>
</div>
<div id = 'scrapContent' style = 'overflow:scroll;'>
</div>
</div>PW_C_Scrap.php
Code: Select all
<?php
##session_start();
##error_reporting( E_ALL );
$action = ( ( isset( $_REQUEST['action'] ) === TRUE ) ? $_REQUEST['action'] : '' );
$output = '';
print_r( $_REQUEST );
switch( $action ){
case 'insert':{
echo $_POST['poster'] . 'posted' . $_POST['msg']; exit;
}
}
?>