Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
170
rated 0 times [  176] [ 6]  / answers: 1 / hits: 28233  / 14 Years ago, mon, august 23, 2010, 12:00:00

my post looks like this:



$.post('/ajaxvalidate/1', {nid: nid}, function(data) {


I get the Uncaught SyntaxError: Unexpected token : error in google chrome.



I understand that I need to set a content type or something, from this question:
Uncaught SyntaxError: Unexpected token :



I don't understand how to do it.



http://api.jquery.com/jQuery.post/ has no examples. :( Thanks.


More From » jquery

 Answers
8

There are a number of examples on the jQuery.post API page that you linked to. They're about 1/3 of the way down the page. The last example on the page shows passing the 'json' content type in this method.



Here's a sample of doing a jQuery post -- and this works in jsFiddle without issue:



$(function() {
$.post(/ajax_json_echo/, {html: stuff}, function(data) { alert(data.post_response.html);}, json);
});


I'm passing my data to the service using 'json' as my data type.



So, are you sure there isn't a server side error happening. Try running your call through Fiddler or Firebug and see what you get back. Also, what type of data is your service expecting?



Update your post with what you see and I'll update my answer accordingly.



Hope this helps.


[#95840] Friday, August 20, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yosefleod

Total Points: 113
Total Questions: 100
Total Answers: 115

Location: Egypt
Member since Tue, May 3, 2022
2 Years ago
;