1

I am editing a div and trying to send new text in the div with the url, I can't figure out how to append new text at the end of the url, I tried the method below to no success.

$(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);
}
});
DN0300
  • 864
  • 2
  • 12
  • 27
  • 2
    uh, the url is the address of the script you awnt to send the data to. `http://example.com/whatever.php`, you're trying to do the equivalent of `http://example.com/whatever.phpOnce upon a time, blah blah`, which is NOT a valid url. – Marc B Jul 13 '16 at 17:58

1 Answers1

0

try

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

Or

var mydata = $("#edit").text();
$.ajax({
    type: 'post',
    url: "url",
    data: { editable: mydata},
    success: function(event) {
        console.log($("#edit").text());
    }
});
  • neither of them worked, I have to pass the new data in the url. When I do it manually it works fine – DN0300 Jul 13 '16 at 18:18
  • when you manually https://example.com?data="whatever" this is a GET Request not a POST Request – ahmadelmorshedy Jul 13 '16 at 18:21
  • Try this http://stackoverflow.com/questions/18697034/how-to-pass-parameters-in-ajax-post – ahmadelmorshedy Jul 13 '16 at 18:22
  • yea so the request is suppose to be look like "example.com/newtext" – DN0300 Jul 13 '16 at 18:32
  • wait a minute... The request "example.com/newtext" is a request to route "/newtext" in domain "example.com", this is not passing parameters to the url, Do you understand the difference??? – ahmadelmorshedy Jul 13 '16 at 18:41
  • Yea I understand the difference, thats why I have been trying to append the variable at the end of the url like this "url"+$("#edit").text(), – DN0300 Jul 13 '16 at 18:54
  • What if you try var finalurl = "yourdomain.com/" + $("#edit").text(); $.ajax({ type: 'post', url: finalurl, success: function(event) { console.log($("#edit").text()); } }); – ahmadelmorshedy Jul 13 '16 at 19:38
  • No didn't work :( it just ignores the last part and posts it to the url only – DN0300 Jul 13 '16 at 20:54