How to get rid from ?callback=myCallback&_=1340513330866? - javascript

I'm trying to capture data from an HTML page that is on the another website. I need to capture that data and save it into my site. That's why I used cross domain ajax like this
var myCallback = function(data) {
console.log(data);
};
var formData = $('.data-capture-form').serialize();
$.ajax({
url: 'http://prospectbank.co.uk/leads/capt',
type: 'GET',
data: formData,
dataType: 'jsonp',
crossDomain: true,
jsonp: 'callback',
jsonpCallback: 'myCallback'
}).done(function(res) {
console.log(res);
}).fail(function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR, textStatus, errorThrown);
});
Then I get this error
Any help? Thanks

The response from http://prospectbank.co.uk/leads/capt?_=1340513330866? is wrong formatted JSON.
{"status":true}
It should be
{status:true}

Related

How to get each data before ajaxSend in JSON not after complete/success

I want all the ajax params before sending an ajax request in JSON format and I need to encrypt each value in JSON and again pass to the ajax request.
I get data in URI format as see in below code, not in JSON. How can I get that?
Around 200 Ajax in this format:
$.ajax({
type: "POST",
url: site_url + "user/user/login_action",
data: login_parms,
success: function (data) {
},
error: function (xhr, textStatus, errorThrown) {
}
});
Before Ajax Call:
$(document).ajaxSend(function(event, jqxhr, settings) {
console.log("settings :",settings.data);
});
Console log:
settings : vEmail=disha.c1%40grr.la&vPassword=123456789
Also if in AJAX use formData then how we can get each value of form data?
If you want to send a AJAX JSON CALL you must to use:
$.ajax({
type: "POST",
url: site_url + "user/user/login_action",
dataType: "json",
async: false,
contentType: "application/json",
data: JSON.stringify(login_parms),
success: function (data) {
},
error: function (xhr, textStatus, errorThrown) {
}
});
if you want to modify the param:
$.ajax({
beforeSend: function(xhr){
this.data
}
});

Firebase Dynamic Link Creation With JavaScript

var object={
"longDynamicLink": "https://[APP_NAME].page.link/?link=[LINK_HERE]",
"suffix":{
"option":"SHORT"
}
}
$.ajax({
url: 'https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=[KEY_HERE]',
type: 'POST',
dataType: "json",
data: object,
success: function(response, textStatus, jqXHR) {
alert(response.shortLink);
},
error: function(jqXHR, textStatus, errorThrown){
alert(textStatus, errorThrown);
}
});
The above code works if the "suffix" is deleted from the request. That makes an "UNGUESSABLE" url, but I want a short URL. As stated in the documentation at https://firebase.google.com/docs/dynamic-links/rest?authuser=0 I added the suffix option parameter, but it results with a 400 response. Any ideas why?
I haven't ever tried this but, ...
POST https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=api_key
var params = {
"longDynamicLink": "https://example.page.link/?link=http://www.example.com/&apn=com.example.android&ibi=com.example.ios",
"suffix": {
"option": "SHORT"
}
}
$.ajax({
url: 'https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=[KEY_HERE]',
type: 'POST',
data: jQuery.param(params) ,
contentType: "application/json",
success: function (response) {
alert(response.status);
},
error: function () {
alert("error");
}
});

showing 400 (Bad Request) in ajax

I am using cordova and while doing json i am getting an error "Failed to load resource: the server responded with a status of 400 (Bad Request)".
But the same code when I run it on postman is getting the right answer.Please help me to solve this problem.
The code is:
$.ajax({
url: url,
type: "POST",
async: false,
ContentType: "application/json; charset=utf-8",
data: jData,
dataType: "json",
success: function(response) {
console.log(response)
},
error: function(jqXHR, textStatus, errorThrown) {
},
});
And a screenshot of the right answer on the postman is also given for your reference
you need to stringify the JSON data was sending
$.ajax({
type: 'POST',
url: url,
async: false,
data: JSON.stringify(jData),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(response) {
console.log(response)
},
error: function(jqXHR, textStatus, errorThrown) {
}
});
Try removing the open and closing brackets around your jData
var jData = {};
Not
var jData = [{}];

Post AJAX API Javascript SAPUI5 failed

I want to use POST method with AJAX in SAPUI5 javascript but I found an error.
var url = "https://xxxx*xxxx.co.id:8877/TaspenSAP/SimpanDosirPunah";
$.ajax({
type: "POST",
url: url,
data: JSON.stringify({
nomorDosir: "01001961288",
kodeCabang: "A02"
}),
dataType: "json",
async: false,
contentType: 'application/json; charset=utf-8',
success: function(data, textStatus, xhr){
console.log("sukses: " + data + " " + JSON.stringify(xhr));
},
error: function (e,xhr,textStatus,err,data) {
console.log(e);
console.log(xhr);
console.log(textStatus);
console.log(err);
}
});
error:
I already did change code with dataType=text, or data: {nomorDosir: "01001961288", kodeCabang: "A02"} (without stringify), but I not yet find the solution. How to fix this problem?
Thanks.
Bobby
Not sure what your use case is but if you are trying to post to an oData service, it might be much easier to use SAPs createEntry method where the URL is the path to the model you want to post to and your JSON are the properties:
var oModel = new sap.ui.model.odata.v2.ODataModel("https://services.odata.org/V2/OData/OData.svc/");
//oModel should use your service uri
var url = "https://xxxx*xxxx.co.id:8877/TaspenSAP/SimpanDosirPunah";
oModel.createEntry(url, {
properties: {
nomorDosir: "01001961288",
kodeCabang: "A02"
}
}, {
method: "POST",
success: function(response) {
alert(JSON.stringify(response));
//do something
},
error: function(error) {
alert(JSON.stringify(error));
}
});
oModel.submitChanges();
What you have is wrong json format, you have:
data: JSON.stringify({nomorDosir: "01001961288", kodeCabang: "A02"}),
Which actually should be:
data: {"nomorDosir": "01001961288", "kodeCabang": "A02"},
Which then you don't need to do a json.stringify on, because it already IS a json format. Hope this will help you out.
Which you could also try is setting a variable outside like this:
var url = "https://xxxx*xxxx.co.id:8877/TaspenSAP/SimpanDosirPunah";
var json = {"nomorDosir": "01001961288", "kodeCabang": "A02"};
$.ajax({
type: "POST",
url: url,
data: json,
dataType: "json",
async: false,
contentType: 'application/json; charset=utf-8',
success: function(data, textStatus, xhr){
console.log("sukses: "+data+" "+JSON.stringify(xhr));
},
error: function (e,xhr,textStatus,err,data) {
console.log(e);
console.log(xhr);
console.log(textStatus);
console.log(err);
}
});

Getting string serves reply ajax and jquery

i got from my customer string that I need to get to the server and get an answer.
this is the string:
http://XXX.YYY.DDD.WWW:8082/My_ws?Myapp=Myprice&Mydip=123&itemno=123456
and i get any string as Result.
i try this in ajax and jQuery:
$.ajax({
ServiceCallID: 1,
url: MyString,
type: 'POST',
data: '{"itemno": "' + itemno+ '"}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success:
function (data, textStatus, XMLHttpRequest) {
ALL = (data.d).toString();
}
},
error:
function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
how to "talk" with the server and get the Result from my string ?
thanks

Categories

Resources