Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-14-2012, 07:02 PM   PM User | #1
sonic656
New Coder

 
Join Date: Sep 2011
Location: 127.0.0.1
Posts: 62
Thanks: 18
Thanked 0 Times in 0 Posts
sonic656 is an unknown quantity at this point
ajax script not working :( plz help

My code:

JAVASCRIPT PART:
Code:
function test() {
	$.ajax({
		url: '../ajax/test.php',
	}).done(function(data) { 
		return data;
	});
}
alert(test());
PHP PART:
Code:
<?php
	echo "Hello, world!";
?>

What I'm doing wrong ? :/



PS: Im loaing jQuery mini 1.8 from jquery website.
__________________
My website is here: http://www.moowdesign.eu/. It is not complete yet, and I want to add language translations for some languages(including english).
sonic656 is offline   Reply With Quote
Old 11-14-2012, 07:18 PM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 945
Thanks: 7
Thanked 97 Times in 97 Posts
WolfShade is an unknown quantity at this point
Do you mean to go back one directory/folder and then access a sub-folder called "ajax"?

If the URL is the only argument, remove the comma after test.php',
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 11-14-2012, 07:18 PM   PM User | #3
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
You tried to return something from your "outer" function test(), but instead you only return something from the "inner" anonymous closure function.

General rule: Every action that depends on the outcome of an asynchronous method must be run inside the callback of that method or must be called from that callback. Returning anything doesn't make any sense because at the time the callback is run, the outer function has already finished.
devnull69 is offline   Reply With Quote
Old 11-14-2012, 07:45 PM   PM User | #4
sonic656
New Coder

 
Join Date: Sep 2011
Location: 127.0.0.1
Posts: 62
Thanks: 18
Thanked 0 Times in 0 Posts
sonic656 is an unknown quantity at this point
Soo.....How can I edit it, so it will work?

PS: removing that comma after test.php' did not affect anything
__________________
My website is here: http://www.moowdesign.eu/. It is not complete yet, and I want to add language translations for some languages(including english).

Last edited by sonic656; 11-14-2012 at 07:48 PM..
sonic656 is offline   Reply With Quote
Old 11-14-2012, 08:26 PM   PM User | #5
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Whatever you want to do with "data", just do it inside the .done() method
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
sonic656 (11-15-2012)
Old 11-15-2012, 02:09 PM   PM User | #6
sonic656
New Coder

 
Join Date: Sep 2011
Location: 127.0.0.1
Posts: 62
Thanks: 18
Thanked 0 Times in 0 Posts
sonic656 is an unknown quantity at this point
and what with the return code? how can I return the data?
__________________
My website is here: http://www.moowdesign.eu/. It is not complete yet, and I want to add language translations for some languages(including english).
sonic656 is offline   Reply With Quote
Old 11-15-2012, 02:49 PM   PM User | #7
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
You didn't get me ... technically you can return something from each and every function, but semantically it doesn't make any sense to return something from the callback of an asynchronous method because it will end up "in thin air". The calling method has long finished before the callback is executed so you cannot return anything from it.

So:
Quote:
General rule: Every action that depends on the outcome of an asynchronous method must be run inside the callback of that method or must be called from that callback. Returning anything doesn't make any sense because at the time the callback is run, the outer function has already finished.
devnull69 is offline   Reply With Quote
Old 11-15-2012, 02:55 PM   PM User | #8
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 945
Thanks: 7
Thanked 97 Times in 97 Posts
WolfShade is an unknown quantity at this point
In other words, I don't think you can "return" anything for the alert.. now you should be able to put the alert inside the callback function. Or, alternatively, create a div, give it an id, and use .html() to place the data in it.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:33 AM.


Advertisement
Log in to turn off these ads.