I am trying to concatenate an "http://" to the variable 'bar' if it does not already exist, before sending it to ajax where it will be added to the database and will also be displayed back on the page. I can do this in PHP in the processing script and have it added to the db but that does not put it back on the page (without a refresh).
$('#update').click(function() {
var foo = "http://";
var bar = $('#url').val();
if (bar != '') {
if (!preg_match('#^[a-zA-Z]+://#', bar)) {
var bar = foo.concat(bar);
}
}
$.ajax({
url : 'update_this.php',
method : 'post',
data : {bar:bar},
success : function(response) {
$('#id').children('a[data-target=x]').attr('href',bar);
}
});
});