[英]$.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: 我这样调用Embedly API:
$('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
. 这样我就可以访问动态生成的哈希oembed
,并且我想保存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. 我在嵌入调用的外部和内部都尝试了$.ajax()
调用,这似乎阻止了整个调用都无法嵌入。 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
: 使用冒号而不是等号,并且不要忘记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
是有效的JSON对象:
data: { title : oembed.title }
Note : in JSON, the value of an object's property is separed of its name by a colon ; 注意:在JSON中,对象属性的值由冒号分隔其名称; not an equal sign. 不是等号。
See json.org for a reference of the JSON syntax. 有关JSON语法的参考,请参见json.org 。
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: 也许您想添加一个success
处理程序:
$.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 }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.