I have a result from Fiddler (please see the attached image), how can I get the results where the arrow is pointing to?
This is what I have done so far and thank you:
function GetRefiners() {
$.ajax({
url: "myUrl",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function(data){
$.each(data.d.query, function(list){
});
},
error: function(error){
alert("Error message\n" + JSON.stringify(error));
}
}
);
}
Simply go to the results objects and iterates over it
function GetRefiners() {
$.ajax({
url: "myUrl",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function(data){
$.each(data.d.query.PrimaryQueryResult.RefinementResults.Refiners.results.Entries.results, function(list){
callWhatYouNeed();
}
};
},
error: function(error){
alert("Error message\n" + JSON.stringify(error));
}
}
);
}
Related
I've a calculated column(return data type: date and time) in SharePoint 2013 list, am trying to retrieve value and display in a form.
I'm using the below function to get the value from SharePoint list:
function getData(g_Data_URL) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + g_Data_URL,
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function(data) {
var Onsite= new Date(data.d.Onsite);
$('#Ontime').data("DateTimePicker").date(Onsite);
},
error: function(error) {
console.log(JSON.stringify(error));
}
});
}
Please let me know if the syntax of calling the value is incorrect.
Any help is appreciated
From your code, your calculated column name is "Onsite". And I did a test on my end, it works well to get the value:
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('ct3')/items(1)",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function(data) {
var Onsite= new Date(data.d.Onsite);
console.log(Onsite);
},
error: function(error) {
console.log(JSON.stringify(error));
}
});
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");
}
});
here is my code
$.ajax({
url: "DataGridServlet.htm",
type: "GET",
traditional: true,
dataType: 'JSON',
cache: false,
contentType:"application/json",
success: function (response){
console.log(response);
}
});
});
and when i am sending request to controller.. every is working but wnem returning JSONObject i am getting thya status code as 406 not acceptable.
and below spring controller code
#RequestMapping(value="/DataGridServlet.htm", method = RequestMethod.GET,produces="application/json",headers="Accept=*/*")
public #ResponseBody JSONObject getReturnData()
{
System.out.println("control came into conroller");
JSONObject dataObject=new JSONObject();
dataObject=jqTabsGridDataDao.getTabsData();
System.out.println("controller data"+dataObject);
return dataObject;
}
any one can help me?
Change
#RequestMapping(value="/DataGridServlet.htm", method = RequestMethod.GET,produces="application/json",headers="Accept=*/*")
to
#RequestMapping(value="/DataGridServlet.htm", method = RequestMethod.GET,produces="application/json",)
and this
$.ajax({
url: "DataGridServlet.htm",
type: "GET",
traditional: true,
dataType: 'JSON',
cache: false,
contentType:"application/json",
success: function (response){
console.log(response);
}
});
});
to
$.ajax({
url: 'DataGridServlet.htm',
type: "GET",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
success: function(result) {
alert(result + " result ");
},
error: function(resError) {
//alert(resError + " Error ");
}
});
I am not able to view the JSON response from the server on my HTML page. Request is sent to server once the user clicks on the button. By making an API call from AJAX in javascript, I am trying to display the response.
Here is my html page:
This is the response which I get using POSTMAN:
{
"status": 1,
"success_Result": {
"names": [
{
"id": 1,
"name": "text1"
},
{
"id": 4,
"name": "text2"
},
{
"id": 5,
"name": "text3"
}
]
}
}
This is my javascript:
$("#search").click(function()
{
$.ajax(
{
type: "GET",
url: "http://localhost:8080/********/1/1/1?start_date=2017-02-10",
async:true,
dataType : 'jsonp',
crossDomain:true,
contentType: "application/json; charset=utf-8",
headers:
{
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'x-requested-with'
},
success: function(result)
{
try
{
console.log(JSON.stringify(result));
alert(result);
//$("#display").html(result);
}
catch (error)
{
alert("error found");
}
},
error: function(xhr, status, err)
{
console.log(err.message);
}
});
});
Firebug: console
I can view the response here by clicking on the arrow.
I tried using datatype: "json" in javascript. and I got this in the console. And nothing i could see in the HTML page.
$("#search").click(function()
{
$.ajax(
{
type: "GET",
url: "http://localhost:8080/*******/1/1/1?start_date=2017-02-10",
async:true,
dataType : 'json',
crossDomain:true,
contentType: "application/json; charset=utf-8",
success: function(result)
{
try
{
console.log(JSON.stringify(result));
alert(result);
//$("#display").html(result);
}
catch (error)
{
alert("error found");
}
},
error: function(xhr, status, err)
{
console.log(err.message);
}
});
});
console:
I tried other possible ways too....
// using XMLHttpRequest
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://localhost:8080/*******/1/1/1?start_date=2017-02-10", true);
xhr.onload = function ()
{
try
{
$("#display").html("hello");
console.log(xhr.responseText);
}
catch (ex)
{
alert('Error parsing response.');
}
};
try
{
xhr.send();
}
catch (ex)
{
alert(ex.message);
}
console:
Cross-origin resource sharing, Same origin policy error.
I don't know where i am going wrong. If anyone could help me out, it will be great. Please.
###########UPDATE###########
I tried this code now as per suggestions,
$.ajax(
{
type: "GET",
url: "http://localhost:8080/*******/1/1/1?start_date=2017-02-10",
dataType : 'json',
contentType: "application/json; charset=utf-8",
success: function(result)
{
try
{
console.log(JSON.stringify(result));
alert(JSON.stringify(result));
}
catch (error)
{
alert("error found");
}
},
error: function(xhr, status, err)
{
console.log(err.message);
}
});
I got this is my console:
Headers in above image has something to say about CORS ?? Is it enabled or disabled ?? How to check ??
I am quite green when it comes to AJAX and am trying to get an email address from an ASP.Net code behind function
When using the below code I am getting the error as per the title of this issue.
This is the code I am using
$('.txtRequester').focusout(function () {
console.log("textBox has lost focus");
function ShowCurrentTime() {
$.ajax({
type: "POST",
url: "Default.aspx/FindEmailAddress",
data: '{id: "' + $("txtRequester").val + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
}
function OnSuccess(response) {
alert(response.d);
}
});
which is an adaptation of the code from this site.
ASP.Net Snippets
When changing the line
success: OnSuccess to success: alert(response) or success: alert(data)
I get the error up, but if I use success: alert("ok") I get the message saying ok so I suspect that I am getting into the function as below.
<System.Web.Services.WebMethod()> _
Public Shared Function FindEmailAddress(ByVal id As String) As String
Dim response As String = GetEmail(id)
Return response
End Function
I would be extremely grateful if someone to help me and let me know where I am going wrong on this one.
thanks
I think you have can check the state of failure by using this code below as I think there is wrong syntax used by you.
$('.txtRequester').focusout(function () {
console.log("textBox has lost focus");
function ShowCurrentTime() {
$.ajax({
type: "POST",
url: "Default.aspx/FindEmailAddress",
data: JSON.stringify({id: ' + $(".txtRequester").val() + ' }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data, status, header){
console.log(data);
},
error: function (response) {
alert(response.d);
}
});
}
});
then definitely you will get error response, if your success won't hit.
You have not called the function thats why its never get called.
$('.txtRequester').focusout(function () {
console.log("textBox has lost focus");
ShowCurrentTime();
});
function ShowCurrentTime() {
$.ajax({
type: "POST",
url: "Default.aspx/FindEmailAddress",
data: '{id: "' + $("txtRequester").val() + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
Onsuccess(response);
},
failure: function (response) {
alert(response.d);
}
});
}
function OnSuccess(response) {
alert(response.d);
}
This will help :)
use ajax directly ,
$('.txtRequester').focusout(function () {
console.log("textBox has lost focus");
var cond = $(".txtRequester").val();
$.ajax({
type: "POST",
url: "Default.aspx/FindEmailAddress",
data: {id:cond},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response){
alert(response.d);
},
failure: function (response) {
alert(response.d);
}
});
});
Change $('.txtRequester') to $('#txtRequester')
and
Change $("txtRequester").val to $('#txtRequester').val()