Why the progress function of ng-file-upload was just triggered two times? - ng-file-upload

I want to use the progress function to show the progress of uploading. However, the progress function was just called two times at the beginning. So the value of progress is always 0.
<input name="file" data-ngf-select type="file" style="display: none" ng-model="uploadCtrl.file"
ng-show="false" ngf-max-size="20MB" ngf-change="uploadCtrl.invalidFile()"
accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
Upload.upload(
{
url: PathUtils.qualifiedAPIPath(url),
headers: {
'Access-Control-Allow-Origin': '*'
},
data: param,
method: 'post',
arrayKey: ''
}).then(success, function (error) {
conn.errorHandler(error.data, error.status)
}, progress);
function progress() {
if (document.getElementById("mask") != null) {
document.getElementById("mask").style.display = 'block';
$http({
'url': PathUtils.qualifiedAPIPath("progress"),
'method': "get"
}).success(function (res) {
document.getElementById("mask-progress").innerHTML = res + '%';
}).error(conn.errorHandler);
}
}

Related

How to restrict user from submitting a form twice in sharepoint?

I'm working on a sharepoint forms
And I need to block edition for users after they submitted a date (data format), but I don't know if sharepoint allows it
Someone knows how can I do it?
For OOB list form, you could use presaveaction to do client validation.
In this function, you could call rest api to check whether the item submitted already, if submitted, return false then the form won't be saved.
Sample demo:
<script type="text/javascript" src="/_layouts/15/JS/jquery.min.js"></script>
<script type="text/javascript">
function PreSaveAction() {
var check = false;
var listid = _spPageContextInfo.pageListId.replace('{', '').replace('}', '');
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists(guid'" + listid + "')/items",
type: 'GET',
async: false,
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
},
success: function (data, textStatus, jqXHR) {
var count = data.d.results.length;
if (count < 5) {
check = true;
} else {
alert('over max items');
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus);
}
})
return check;
}
</script>

Facing issue as 404 while Ajax call in typo3

I am new in typo3 and used the ajaxselectlist extension but while the time usage I am facing 404 not found an error.
Below code is fetch from ajaxselectlist/Resources/Templates/OptionRecord/List.html
<script>
jQuery(document).ready(function ($) {
var form = $('#ajaxselectlist-form');
var selectForm = $('.ajaxFormOption');
var controllerpath = $("#uri_hidden").val();
var resultContainer = $('#ajaxCallResult');
var service = {
ajaxCall: function (data) {
console.log("---->"+data.serialize());
$.ajax({
url: controllerpath,
cache: false,
data: {'uid':'1'},
success: function (result) {
resultContainer.html(result).fadeIn('slow');
},
error: function (jqXHR, textStatus, errorThrow) {
resultContainer.html('Ajax request - ' + textStatus + ': ' + errorThrow).fadeIn('fast');
}
});
}
};
form.submit(function (ev) {
ev.preventDefault();
service.ajaxCall($(this));
});
selectForm.change(function () {
resultContainer.fadeOut('slow');
form.submit();
});
selectForm.trigger('change');
});
</script>

Get all replies in SharePoint Sitefeed using REST api

I'm trying to use RESTful services to return all replies in a SharePoint sitefeed. Currently, I am successfully using this code to retrieve the sitefeed's posts:
function getFeed(){
var feed;
var reply;
var rCounter;
$.ajax({
url: "https://<mysite>.sharepoint.com/<sitename>/_api/social.feed/actor(item=#v)/feed?#v=%27https://<mysite>.sharepoint.com/<sitename>/newsfeed.aspx%27",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
// Returning the results
myFeed = $(data);
console.log(myFeed);
for (i = 0; i < myFeed[0].d.SocialFeed.Threads.results.length; i++) {
feed = (myFeed[0].d.SocialFeed.Threads.results[i].RootPost.Text);
console.log(myFeed[0].d.SocialFeed.Threads.results[0].Actors.results[1].Name + ": " + feed);
if (myFeed[0].d.SocialFeed.Threads.results[i].Replies.results.length >0){
rCounter = myFeed[0].d.SocialFeed.Threads.results[i].Replies.results.length;
for (j = 0; j < myFeed[0].d.SocialFeed.Threads.results[i].Replies.results.length; j++) {
rCounter--;
reply = myFeed[0].d.SocialFeed.Threads.results[i].Replies.results[rCounter].Text;
console.log(reply);
}
}
console.log("* * * * * * * * *");
}
},
error: function (data) {
console.log("ERROR - SEE CODE");
}
});
}
However, this gives me the posts but with only the two latest replies. According to this MSDN post, I need to use a POST method to get all replies and pass in the thread ID. So I made a new function:
function getPost(){
$.ajax({
url: "https://<mysite>.sharepoint.com/<sitename>/_api/social.feed/post(ID=ai)/?#ai='8.211b75cd6dc84fe4bc6c3e9f46971f51.97717348cd3048768103d55751dc0e2d.211b75cd6dc84fe4bc6c3e9f46971f51.819bde2276b948a8a120964289476489.17c08f26b90a4b659ff1fcfb0ede4025.5.5.1'",
method: "POST",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
// Returning the results
console.log($(data));
},
error: function (data) {
console.log("ERROR - SEE CODE");
}
});
}
When I run this new function, I get a 403 (FORBIDDEN) error. Can someone tell me what I'm doing wrong?
try passing headers like below.
function getPost(){
$.ajax({
url: "https://<mysite>.sharepoint.com/<sitename>/_api/social.feed/post(ID=ai)/?#ai='8.211b75cd6dc84fe4bc6c3e9f46971f51.97717348cd3048768103d55751dc0e2d.211b75cd6dc84fe4bc6c3e9f46971f51.819bde2276b948a8a120964289476489.17c08f26b90a4b659ff1fcfb0ede4025.5.5.1'",
method: "POST",
headers: { "Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val() },
success: function (data) {
// Returning the results
console.log($(data));
},
error: function (data) {
console.log("ERROR - SEE CODE");
}
});
}

Decoding response error in extjs

I am doing the following stuff when a form is submitted. But I get this error:
Error decoding response: SyntaxError: syntax error
Here is my onSubmit success function:
onSubmit: function() {
var vals = this.form.getValues();
Ext.Ajax.request({
url: 'ticketSession.php',
jsonData: {
"function": "sessionTicket",
"parameters": {
"ticket": vals['ticket']
}
},
success: function( result, request ) {
var obj = Ext.decode( result.responseText );
if( obj.success ) {
//alert ('got here');
th.ticketWindow.hide();
Web.Dashboard.loadDefault();
}
},
Here is my ticketSession.php
<?php
function sessionTicket($ticket) {
if( $_REQUEST['ticket'] ) {
session_start();
$ticket = $_REQUEST['ticket'];
$_SESSION['ticket'] = $ticket;
echo("{'success':'true'}");
}
echo "{'failure':'true', 'Error':'No ticket Number found'}");
}
?>
I also modified my onsubmit function but didnt work:
Ext.Ajax.request({
url: 'ticketSession.php',
method: 'POST',
params: {
ticket: vals['ticket']
},
i am simply echoing this but I still get that error
echo("{'success':'true'}");
Maybe this can help you. It's a working example of an ajax-request which is nested in a handler.
var deleteFoldersUrl = '<?php echo $html->url('/trees/delete/') ?>';
function(){
var n = tree.getSelectionModel().getSelectedNode();
//FolderID
var params = {'folder_id':n['id']};
Ext.Ajax.request({
url:deleteFoldersUrl,
params:params,
success:function(response, request) {
if (response.responseText == '{success:false}'){
request.failure();
} else {
Ext.Msg.alert('Success);
}
},
failure:function() {
Ext.Msg.alert('Error');
}
});
}

Send a wall post using Jquery's AJAX (Post)

I'm trying to post a wall message from a local desktop application (I can't use the FB JS SDK).
Here's a a snippet of my code
var url = "https://graph.facebook.com/me/feed";
var params = "access_token=" + token + "&message=" + encodeURI(text);
$.ajax({
crossDomain: true,
data: params,
dataType: "jsonp",
url: url,
type: 'POST',
success: function (data) {
if (callback) {
var isOK = (data && data.id && !data.error);
callback(isOK, data);
}
},
error: function (data, e1, e2) {
}
});
The request ignores the message parameter.
I receive a list of feeds as it were a GET request.
I've tried to set the parameters as map but it didn't help.
BTW - when using CURL (in C++) i manage to post the data correctly.
Any ideas why it ignores the parameters?
I would put the "params" into the data element like so:
var url = "https://graph.facebook.com/me/feed";
$.ajax({
crossDomain: true,
data: { access_token: token, message: text },
dataType: "jsonp",
url: url,
type: 'POST',
success: function (data) {
if (callback) {
var isOK = (data && data.id && !data.error);
callback(isOK, data);
}
},
error: function (data, e1, e2) {
}
});
Let jQuery encode the parameters from there.
Below worked fine in Jquery 1.6.4 + jquery.mobile-1.0rc2 by setting $.mobile.allowCrossDomainPages = true; in mobileinit bind
$.ajax( {
url : "https://graph.facebook.com/me/feed",
type : "POST",
data : "access_token=" + your_access_token + "&message=my first wall post",
cache : false,
success : function(res) {
if (!response || response.error) {
alert("Couldn't Publish Data");
} else {
alert("Message successfully posted to your wall");
}
},
error : function(xhr, textStatus, errorThrown) {
alert(xhr.responseText);
}
});