最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery Uncaught SyntaxError: Unexpected token : - Stack Overflow

programmeradmin5浏览0评论

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.

.post/ has no examples. :( Thanks.

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./jQuery.post/ has no examples. :( Thanks.

Share Improve this question edited May 23, 2017 at 11:53 CommunityBot 11 silver badge asked Aug 23, 2010 at 21:08 JSNewbieJSNewbie 3353 gold badges5 silver badges10 bronze badges 2
  • Are you missing your success function callback implementation? I'm assuming it was cut-off when you pasted the code. – David Hoerster Commented Aug 23, 2010 at 21:19
  • I am having similar problem. Can someone help me with this ticket stackoverflow./questions/14420920/… – user1993920 Commented Jan 20, 2013 at 2:29
Add a ment  | 

2 Answers 2

Reset to default 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.

I got the same error when I forget to close normally $(document).ready(function(){ with ); (not only })

发布评论

评论列表(0)

  1. 暂无评论