简体   繁体   中英

$.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?

您在以下位置缺少逗号:

url: "/videos"

使用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

$.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/ */
       }
 });

尝试将您的数据json声明更改为

{ "title": oembed.title }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM