【问题标题】:Can't get a variable to append to ajax url无法获取要附加到 ajax url 的变量
【发布时间】:2016-07-13 17:55:11
【问题描述】:

我正在编辑一个 div 并尝试使用 url 在 div 中发送新文本,我不知道如何在 url 末尾附加新文本,我尝试了下面的方法没有成功。

$(document).ready(function() {
$('.edit').editable(function(value, settings) {
        var $this = $("#edit").text();
        $.ajax({
            type: 'post',
            url: "url"+$this,
            success: function(event) {
            console.log($("#edit").text());
            }
        });
     return(value);
}
});

【问题讨论】:

  • 呃,url 是你要发送数据的脚本的地址。 http://example.com/whatever.php,您正在尝试执行与 http://example.com/whatever.phpOnce upon a time, blah blah 等效的操作,这不是有效的 url。

标签: jquery ajax jeditable


【解决方案1】:

试试

var $this = $("#edit").text();
$.ajax({
    type: 'post',
    url: "url",
    data: { editable: $this},
    success: function(event) {
        console.log($("#edit").text());
    }
});

或者

var mydata = $("#edit").text();
$.ajax({
    type: 'post',
    url: "url",
    data: { editable: mydata},
    success: function(event) {
        console.log($("#edit").text());
    }
});

【讨论】:

  • 它们都不起作用,我必须在 url 中传递新数据。当我手动操作时,它工作正常
  • 当你手动 example.com?data="whatever" 这是一个 GET 请求而不是一个 POST 请求
  • 是的,所以请求看起来像“example.com/newtext”
  • 等一下......请求“example.com/newtext”是在域“example.com”中路由“/newtext”的请求,这不是将参数传递给url,做你明白区别???
猜你喜欢
  • 2019-09-08
  • 2014-02-20
  • 1970-01-01
  • 2015-02-13
  • 1970-01-01
  • 2017-04-21
  • 1970-01-01
  • 2018-06-27
  • 2021-01-08
相关资源
最近更新 更多