By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,934 Members | 1,538 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,934 IT Pros & Developers. It's quick & easy.

Ajax Request problem

P: 42
Hello people.

I have a website portal where I am trying to delete an object, by pressing a button. It does not work and I am getting an error. The HTML part of the request is following:

[HTML]<a href="javascript:makeRequest('set/post.php?actueel&del&[[ID]]');" onclick="return confirm('Weet u zeker dat u dit item wilt verwijderen?')" onmouseover="dragable = false" onmouseout="dragable = true"><img src="[[url]]images/delete.jpg" height="20" width="20" border="0" alt="Verwijderen / Delete" align="absmiddle"/>[/HTML]


Where ID will be replaced by the record identifier.


makeRequest on Javascript looks like following:
Expand|Select|Wrap|Line Numbers
  1. function makeRequest(url,object) {
  2.     xhr = new XHR(url,object);
  3.  
  4.     }
  5. //Constructor
  6. function XHR(url,object) {
  7.     var http_request = null;
  8.     this._load(url,object);
  9. }
  10.  
  11. XHR.prototype._load = function(url,object) {
  12.     /*var _this = this;
  13.     this.http_request.onreadystatechange = function(){_this.getRequest()};
  14.     this.http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
  15.     this.http_request.send('xml=<root>' + ((object!=false)?get(document.getElementById(object)):'') +  '</root>');*/
  16.  
  17.     if (document.getElementById('textarea_url')){ 
  18.         document.getElementById('textarea_url').value += url + "\n\n" + ((object!=false)?get(document.getElementById(object)):'');
  19.     }
  20.  
  21.     var xml = ((object!=false)?get(document.getElementById(object)):'');
  22.  
  23.     $.ajax({
  24.         type: "POST",
  25.         url: url,
  26.         data: 'xml=<root>' + xml +  '</root>',
  27.         async: false,
  28.         complete: function(msg){
  29.             if (document.getElementById('textarea_code')) document.getElementById('textarea_code').value = msg;
  30.             try {
  31.                 //alert();
  32.                 var output = msg.responseXML.documentElement;
  33.                 process(output);
  34.             } catch(e) {
  35.                 //alert('niet goed');
  36.             }
  37.         }
  38.     });    
  39. }
The error message in Birebug is following:

$.ajax is not a function
_load("set/post.php?actueel&del&17", undefined) javascript.js (line 61)
XHR("set/post.php?actueel&del&17", undefined) javascript.js (line 41)
makeRequest("set/post.php?actueel&del&17", undefined) javascript.js (line 35)
[Break on this error] complete: function(msg){

Which makes me think that the 'object' parameter is undefined. This brings me to the real problem - the makeRequest works perfectly with other part in the code (when sending mail). So I cannot completely remove the parameter, but make some changes. This is the point where I don't how to change the code? Any help will be appreciated and more information will be provided.
Sep 16 '08 #1
Share this Question
Share on Google+
2 Replies


Dormilich
Expert Mod 5K+
P: 8,639
although I have no experience with Prototype's syntax, it looks as if $.ajax is supposed to be an object (literal notation!) but I'm missing a = somewhere. You should have a look at the Prototype documentation (or something to make the syntax clear).

regards
Sep 16 '08 #2

rnd me
Expert 100+
P: 427
try combining the actions:


not:
a href="javascript:makeRequest('set/post.php?actueel&del&[[ID]]');" onclick="return confirm('Weet u zeker dat u dit item wilt verwijderen?')"


but:
a href="javascript: if(confirm('Weet u zeker dat u dit item wilt verwijderen?')) { makeRequest('set/post.php?actueel&del&[[ID]]'); }"
Sep 16 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.