BarryOg
7 Jul 2007, 11:13 AM
I seem to have found a solution or workaround but still don't know why Ext.Ajax.request was throwing a syntax error.
Hey everyone,
Just starting to learn ext and unfortunately js at the same time. I'm getting a repeated problem when trying to make an Ext.Ajax.request call. The error I'm getting in firebug is as follows: "Ext.Ajax has no properties"
What I'm trying to do is pass a json string to a php file which decodes it and takes an action against a mysql database. Now I'm pretty sure the json stuff is ok and the php/db as I got all this working with msg.load() but I wanted to be able to make requests against the db without having to go through a div. I've tried everything I can think of, changing all the params, reading the documentation, searching the forums and copying and pasting several examples all to no avail. So I'm guessing I've made so stupid mistake due to my lack of experience with javascript syntax.
You can see the page running here: http://www.liamolony.com/game/ExtStart.html , although this may change as I continue to work on it.
Here's my code ExtStart.js
Ext.onReady(function() {
Ext.get('okButton').on('click', function(){
var records ={'method':'initPlayer',
'PlayerName':'' + Ext.get('name').dom.value,
'PlayerLocX':'10',
'PlayerLocY':'11',
'Health':'101'};
sendCall(records);
});
Ext.get('myButton').on('click', function(){
var records ={'method':'getPlayers'};
var returnedJsonString = sendCall(records, 'myDiv');
var array = returnedJsonString.parseJSON();
Ext.get('myDiv').dom.innerHTML = array[2];
});
function sendCall(dataToSend){
var msg = Ext.get('msg');
Ext.Ajax.request(
{
url: './jsonInterface.php5',
params: Ext.util.JSON.encode(dataToSend),
method: 'post',
callback: function(response) { msg.dom.innerHTML = response.responseText; }
}
);
}
});
Here's my html file as well:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Introduction to Ext: Starter Page</title>
<!-- Include YUI utilities and Ext: -->
<script type="text/javascript" src="../yui/build/utilities/utilities.js"></script>
<script type="text/javascript" src="../ext-1.0.1/adapter/yui/ext-yui-adapter.js"></script>
<script type="text/javascript" src="../ext-1.0.1/ext-all-debug.js"></script>
<script type="text/javascript" src="ExtStart.js"></script>
<!-- <script type="text/javascript" src="json.js"></script>
Include Ext stylesheets here:
<link rel="stylesheet" type="text/css" href="../resources/css/ext-all.css">
<link rel="stylesheet" type="text/css" href="../resources/css/ytheme-vista.css">
-->
<link rel="stylesheet" type="text/css" href="ExtStart.css">
</head>
<body>
<div id="myDiv">This is a test div.</div>
<input type="button" id="myButton" value="My Button" />
<div id="msg" style="visibility: hidden"></div>
Name: <input type="text" id="name" /><br />
<input type="button" id="okButton" value="OK" />
<div id="updateManager" style="visibility: hidden" />
</body>
</html>
Hey everyone,
Just starting to learn ext and unfortunately js at the same time. I'm getting a repeated problem when trying to make an Ext.Ajax.request call. The error I'm getting in firebug is as follows: "Ext.Ajax has no properties"
What I'm trying to do is pass a json string to a php file which decodes it and takes an action against a mysql database. Now I'm pretty sure the json stuff is ok and the php/db as I got all this working with msg.load() but I wanted to be able to make requests against the db without having to go through a div. I've tried everything I can think of, changing all the params, reading the documentation, searching the forums and copying and pasting several examples all to no avail. So I'm guessing I've made so stupid mistake due to my lack of experience with javascript syntax.
You can see the page running here: http://www.liamolony.com/game/ExtStart.html , although this may change as I continue to work on it.
Here's my code ExtStart.js
Ext.onReady(function() {
Ext.get('okButton').on('click', function(){
var records ={'method':'initPlayer',
'PlayerName':'' + Ext.get('name').dom.value,
'PlayerLocX':'10',
'PlayerLocY':'11',
'Health':'101'};
sendCall(records);
});
Ext.get('myButton').on('click', function(){
var records ={'method':'getPlayers'};
var returnedJsonString = sendCall(records, 'myDiv');
var array = returnedJsonString.parseJSON();
Ext.get('myDiv').dom.innerHTML = array[2];
});
function sendCall(dataToSend){
var msg = Ext.get('msg');
Ext.Ajax.request(
{
url: './jsonInterface.php5',
params: Ext.util.JSON.encode(dataToSend),
method: 'post',
callback: function(response) { msg.dom.innerHTML = response.responseText; }
}
);
}
});
Here's my html file as well:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Introduction to Ext: Starter Page</title>
<!-- Include YUI utilities and Ext: -->
<script type="text/javascript" src="../yui/build/utilities/utilities.js"></script>
<script type="text/javascript" src="../ext-1.0.1/adapter/yui/ext-yui-adapter.js"></script>
<script type="text/javascript" src="../ext-1.0.1/ext-all-debug.js"></script>
<script type="text/javascript" src="ExtStart.js"></script>
<!-- <script type="text/javascript" src="json.js"></script>
Include Ext stylesheets here:
<link rel="stylesheet" type="text/css" href="../resources/css/ext-all.css">
<link rel="stylesheet" type="text/css" href="../resources/css/ytheme-vista.css">
-->
<link rel="stylesheet" type="text/css" href="ExtStart.css">
</head>
<body>
<div id="myDiv">This is a test div.</div>
<input type="button" id="myButton" value="My Button" />
<div id="msg" style="visibility: hidden"></div>
Name: <input type="text" id="name" /><br />
<input type="button" id="okButton" value="OK" />
<div id="updateManager" style="visibility: hidden" />
</body>
</html>