开发者

$.ajax() call not working

I'm trying to make this call to send data to the server:

$.ajax({
   type: "POST",
   url: "/videos"
   data: { title = oembed.title }
});

However, 开发者_运维技巧this doesn't seem to work. I make a call to the Embedly API like so:

$('a.oembed').embedly({maxWidth:300,'method':'replace'}).bind('embedly-oembed', function(e, oembed){ 
    });

so that I have access to the dynamically generated hash oembed, and I want to save oembed.title. I tried the $.ajax() call both outside and within the embedly call, and it seems to prevent the entire call to embedly from working. What am I doing wrong?


You're missing a comma after:

url: "/videos"


Try

$.ajax({
   type: "POST",
   url: "/videos",
   data: { title: oembed.title }
});

Also I don't see any handling of the response. Perhaps you would like to add a success handler:

$.ajax({
       type: "POST",
       url: "/videos",
       data: { title: oembed.title },
       success: function(data, textStatus, jqXHR) {
         /* your code here - check http://api.jquery.com/jQuery.ajax/ */
       }
 });


Use data: { title: oembed.title } not =


Use a colon instead of a equals, and don't forget the comma after url:

$.ajax({
 type: "POST",
 url: "/videos",
 data: { title: oembed.title }
});


The following line :

data: { title = oembed.title }

seems not OK ; it should be written this way, so the data is a valid JSON object :

data: { title : oembed.title }

Note : in JSON, the value of an object's property is separed of its name by a colon ; not an equal sign.
See json.org for a reference of the JSON syntax.


Also, you are missing a comma at the end of this line :

url: "/videos"

which should be written like this :

url: "/videos", 


Try changing you data json declaration to

{ "title": oembed.title }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜