I am trying to save an image from android emulator to drupal site using drupalgap, but I am unable to do this, below is my ajax call which I wrote to save the data to drupal site.
My AJAX call
$.ajax({
url: "http://192.168.1.146/drunew/?q=my_services/node.json",
type: 'post',
data: 'node[type]=drupalgap&node[title]=' + encodeURIComponent(title) + '&node[language]=und&node[body][und][0][value]=' + encodeURIComponent(body) + '&node[files][field_filef_und_0]=' + encodeURIComponent(filef),
dataType: 'json',
beforeSend: function (request) {
request.setRequestHeader("X-CSRF-Token", token);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert('page_node_create_submit - failed to login');
console.log(JSON.stringify(XMLHttpRequest));
console.log(JSON.stringify(textStatus));
console.log(JSON.stringify(errorThrown));
},
success: function (data) {
$.mobile.changePage("main.html", "slideup");
}
});
But the above code is not working for file field, then after doing some R&D I got to know that first we have to get the fid, then save it.
Below is the respone after creating the fid for the image.
{"fid":"47","uri":"http://192.168.1.146/drunew/my_services/file/47"}
Here my doubt is how can I integrate this response in my above ajax call to save the image in drupal site.
Any help, thanks..
Once you have the File ID, you pass that along with the Node Create/Update resource like so:
Node Create - POST
http://www.example.com/?q=drupalgap/node.json&title=Hello&type=article&field_images[und][0][fid]=47
Node Update - PUT
http://www.example.com/?q=drupalgap/node/123.json&field_images[und][0][fid]=47
FYI, this feature is now built into DrupalGap core, so you shouldn't have to do much when adding/editing nodes.
Related
I'm working on a progressive page loading script where new pages will load continuously when bottom of the page is reached. I'm using ajax to fetch the data dynamically through jQuery ajax from the server, the return data will return the url of the new post as well as its content.
My problem is what code should I use to submit my returned post url to analytic so that it registers as a valid page view?
$.ajax({
type: 'GET',
url: 'http://somedomain.com/fetch_pages.php',
data: { 'page': this.$loadMoreCounter , 'section': that.$section },
dataType: 'json',
success: function (data) {
//analytic code upon each successful callback.
});
I'm trying to grab some data from the database on a page in typo3 using Ajax . So after a long time looking for the appropriate way to do it , I got convinced that The Ajax Dispatcher is the best tool to do the job . So I created the file following the instructions to be found here.
Now when I make an Ajax call on my page , the console displays a 500 (Internal Server Error).
joined is a snapshot of my console tab.
and this is the jquery function that gets run on an onchange event .
function getContent(id) {
console.log("Start process ...");
$.ajax({
async: 'true',
url: 'index.php',
type: 'POST',
data: {
eID: "ajaxDispatcher",
request: {
pluginName: 'listapp',
controller: 'Pays',
action: 'getMyCos',
arguments: {
'id': id,
}
}
},
dataType: "json",
success: function(result) {
console.log(result);
},
error: function(error) {
console.log(error);
}
});
}
Could someone please help me , I just started developing with this CMS of shit :p
I just had to change the file AjaxDispatcher :
line 101 to: \TYPO3\CMS\Core\Core\Bootstrap::getInstance();
I am making hybrid application using IBM Worklight.
In my windows phone 8.1, when I am running this application, ajax calls returns readyState 4, status 404.
Am I doing something wrong? Any help would be greatly appreciated.
Screen Shot of Project Files Hierarchy Here
AJAX Request Code:
$.ajax({
type: "get",
url: "index.html",
success: function (data) { alert("success" + JSON.stringify(data)); },
error: function (error) { alert("error" + JSON.stringify(error));}
});
You have to append "www/default" before page name, because In windows phone MainPage.xaml is loaded first, which is in root directory. And $.ajax will search from root directory and hence you have to give path as below.
$.ajax({
type: "get",
url: "www/default/index.html",
success: function (data) { alert("success" + JSON.stringify(data)); },
error: function (error) { alert("error" + JSON.stringify(error));}
});
If your application have too many $.ajax or $.get and you don't want to modify each and every request you can use following global ajax settings when your application starts.
$.ajaxSetup({
beforeSend: function (jqXHR, settings) {
settings.url = "www/default/" + settings.url;
}
});
I wanted to retrieve data using ajax, when open the url in browser it showing data but when i execute this url in ajax code error msg function is running however data is showing in browser.
url: "http://live.nayatel.com/?json=1"
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://live.nayatel.com/?json=1",
cache: false,
success: onSuccess,
error: onError
});
});
its a wordpress site and i used a plugin to retrive its data working in browser but not giving response text.
I have two suggestions, since I am not that sure about your problem.
a) Try changing
success: onSuccess,
to
success: function(data, status) {
onSuccess(data, status);
},
b) If that fails, try adding
crossDomain: true,
I have an ajax function that loads within a setInterval as follow :
setInterval(function(){updateChart()}, 5000);
var updateChart = function(){
$.ajax({
url: './script.php',
type: 'post',
dataType: 'json',
cache: false,
data: {'candlesData':candlesData},
success: function(data) {
//alert(data);
//console.log("two");
//console.log(data);
gotData(data);
delete data;
delete candlesData;
},
error: function(xhr, desc, err) {
//console.log(xhr);
//console.log("Details: " + desc + "\nError:" + err);
}
}).done(function() {
});;// end ajax call
}
My browser memory gets SIGNIFICANTLY bigger over time. I tried to diagnose and found out that the POST request in the AJAX data (candlesData) is cached everytime... You can see this in the screenshot (retained data column).
I tried everything to clear the cache but it is not working.
Snapshot of retained data
I fixed this problem.
And I confirm that ajax post doesn't store cache...
The problem was that I had a javascript object which was recreated every time with setInterval function. I used :
objectName.destroy()
that get triggered everytime it reload the function and it resolved the problem.