I have an ajax call such as:
$.ajax({
url: "/query/",
dataType: 'script',
cache: true,
data: {
"" : url,
},
cache: false,
//...
});
whereas: url: "/query/
is a clean URL.
When I make the request i get an URL such as:
http://domain.net/api/query/?=www.whatever.com&_=1434580542713
how could I remove the "?=" section in order to get an URL such as:
http://domain.net/api/query/www.whatever.com&_=1434580542713
Many thanks in advance,
$.ajax({ url: "/query/"+url, dataType: 'script', cache: true, data: {}, cache: false,
Related
I'm trying to display Wordpress blog posts on a different domain. It displays on all browsers except for IE.
Here's my code:
$.ajax({
url: 'www.whatevermywordpresswebsiteis.com/wp-json/wp/v2/posts?_embed&per_page=100',
crossDomain: true,
cache: false,
dataType: "json",
contentType: "application/json; charset=utf-8",
type: 'GET',
async: false,
data: { action : 'get_ajax_posts' },
success: function(data) {
$.each(data, function(i, _post) {
console.log(data);
});
}
});
I've tried to implement XDomainRequest as well but it still fails to work (Jquery $.ajax fails in IE on cross domain calls). I'm not sure what to do at this point.
Here for sending multiple values to the ajax i had done my code like this please have a look
$("#btnSubmit").on("click", function (e) {
e.preventDefault();
var toPost = $('.row_selected input').serialize();
var form_data={
date: $('#transfer_date').val(),
group: $('#lo_group').val(),
name: $('#name').val(),
phone: $('#phone').val(),
location: $('#loc_id').val()
}
$.ajax({
type: 'POST',
url: '<?php echo base_url();?>admin_control/transfer_tool/<?php echo $result->id;?>',
data: 'toPost='+toPost+'&form_data='+form_data,
cache: false,
dataType:"json",
});
});
Here only first value is getting and the second value is not passing,tried a lot but couldn't find a solution.please help me to solve
Convert javascript object to data parameters
use jQuery.param(form_data)
$.ajax({
type: 'POST',
url: 'www.test.com/admin_control/transfer_tool/',
data: 'toPost='+toPost+'&form_data='+jQuery.param(form_data),
cache: false,
dataType:"json",
});
To apply a command to an issue i'm using this code:
$.ajax({
async: false,
type: 'post',
url: "https://golaservices.myjetbrains.com/youtrack/rest/issue/"+e.target.id+"/execute"+"?command="+target.val(),
cache: "true",
dataType: "html"
});
but that brings up this error
You have no access to this resource. Try to log in.
that's why i tried putting that first bit of code like this:
$.ajax({
async: false,
type: 'post',
url: "https://golaservices.myjetbrains.com/youtrack/rest/user/login?login=xxx&password=123",
cache: "true",
dataType: "html",
success: function(output, status, xhr) {
alert(xhr.getResponseHeader('Set-Cookie'));
}
}).done(function (data) {
console.log("in done");
$.ajax({
async: false,
type: 'post',
url: "https://golaservices.myjetbrains.com/youtrack/rest/issue/"+e.target.id+"/execute"+"?command="+target.val(),
cache: "true",
dataType: "html"
});
console.log("after done");
});
but i still get the same error, any idea how to do this ?
/rest/user/login endpoint has been deprecated for a while already and is not recommended for further use. Try permanent tokens instead, they don't require any preflight login requests to be executed.
$.ajax({
type: "post",
url: "https://golaservices.myjetbrains.com/youtrack/rest/issue/" + e.target.id + "/execute" + "?command=" + target.val(),
dataType: "json"
beforeSend: function(xhr) { xhr.setRequestHeader("Authorization", "Bearer " + permanentToken); },
});
var formData = new FormData();
formData.append('name', name.val());
formData.append('email', email.val());
formData.append('contact_number', contact_number.val());
formData.append('barangay', barangay.val());
formData.append('landmark', landmark.val());
formData.append('password', password.val());
formData.append('confirm_password', confirm_password.val());
//Problem start here it came from attributes but I can alert the data and it was fine.
formData.append('image_pin', img_top);
formData.append('img_left', img_left);
formData.append('img_z_index', img_z_index);
formData.append('input_value', input_value);
formData.append('input_top', input_top);
formData.append('input_left', input_left);
$.ajax({
url: 'register',
headers: {'X-CSRF-TOKEN': token.val() },
method: 'post',
processData: false,
contentType: false,
cache: false,
dataType: 'json',
data: formData,
success: function(data){
console.log(data);
},
error: function(){
}
});
//The input works fine but the attributes data is undefined
$request->input('img_top');
$request->input('img_left');
This AJAX call is returning "undefined". I'm not sure what I'm doing wrong and why this isn't working:
var xmlfile;
$.ajax({
type: 'GET',
url: 'sample.xml',
dataType: 'xml',
success: function(data){
xmlfile = $(data);}
});
console.log(xmlfile);
This is likely to be a timing issue since you're referring to the xmlFile variable before the call returns. Instead you have to move the reference into the success callback.
$.ajax({
type: 'GET',
url: 'sample.xml',
dataType: 'xml',
success: function(data){
xmlfile = data;
console.log(xmlfile);
}
});
Try the above.
you can do this by
$.ajax({
type: 'GET',
url: 'sample.xml',
dataType: 'xml',
success: function(data){
xmlfile = data ;}
});
or set the async : false,
you can detect error/problem by debugging so you can see where are you doing wrong
like see alert(data) it it does it mean you are getting successful response by ajax call
var xmlfile;
$.ajax({
type: 'GET',
url: 'sample.xml',
dataType: 'xml',
async : false,
success: function(data){
xmlfile = $(data);}
});
console.log(xmlfile);
try This, you are getting undefined due to asyn call, your log executes before you got result from server