Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
JSON & jQuery $.ajax ... how do I make it work???
Old 01-27-2010, 10:10 AM JSON & jQuery $.ajax ... how do I make it work???
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
Ok so I am working on a project and i'm trying to return JSON to an AJAX call... however it isn't working

Code:
$("a.link-delete-hate").click(function() {
	var hateid = $(this).attr("id").substr(6);
	$.ajax({
	   type: "POST",
	   url: "/ajaxfuncs.php",
	   data: "do=delete&format=json&hate_id=" + hateid,
	   dataType: "json",
//	   contentType: "application/json; charset=utf-8",
	   success: function(data){
	   		alert("Data: " + data.msg);
			$.facebox('' + data.msg + '');
			// If no errors, fade out deleted hate.
			if(data.error == false)
			{
				$("#feed_item_" + hateid).fadeOut(1000);
			}
	   }
	 });
});
Now it should be returning:

Code:
{"error": true, "msg": "Message about call."};
that is sent back with a header of "contentType: "application/json; charset=utf-8"" too...

And yet it seems to return nothing, the thing isnt executed and nothing is returned to the user (no message shown).

Been googling like mad to try and figure out how to properly do this :/

I want to get a JS object of the JSON returned so I can get data.msg and data.error etc :/

Please help. Thanks.
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 02-04-2010, 06:46 AM Re: JSON & jQuery $.ajax ... how do I make it work???
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
*BUMP*

Anyone?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 02-04-2010, 09:38 AM Re: JSON & jQuery $.ajax ... how do I make it work???
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
I've always had trouble with JSON in general, but your syntax looks correct here... Have you tried using jQuery's shortcut method getJSON() ?

What is the result of the alert you're doing in the callback?
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to JSON & jQuery $.ajax ... how do I make it work???
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19041 seconds with 12 queries