hello.js Work Login But publish is not work - asp.net

Sorry, My english is poor.
I'm make some home page, that is gamedict.com.
this home page .Net framework 4.5 and Webform.
Oauth login is work very well. but hello.api(.... 'share'...) is not work.
this page have master page.
<button onclick="OauthLogin('google');" title="Signin to Google" class="zocial icon google"></button>
<button onclick="OauthLogin('facebook');" title="Signin to Facebook" class="zocial icon facebook"></button>
<script type="text/javascript">
function OauthLogin(network) {
hello(network).login();
}
function SignOut(){
var network = $("#hidNetwork").val();
$.ajax({
url: "/AjaxControls/AjaxSignOut.aspx",
type: "POST",
success: function (data) {
hello(network).logout().then(function (){
location.reload();
});
},
error: function (request, status, error) {
alert("getAuthentication code:" + request.status + "\n" + "message:" + request.responseText + "\n" + "error:" + error);
}
});
}
hello.on('auth.login', function (r) {
// Get Profile
hello(r.network).api('/me').then(function (p) {
var isAuthenticated = <%=Page.User.Identity.IsAuthenticated.ToString().ToLower() %>;
if (!isAuthenticated) {
$.ajax({
url: "/AjaxControls/AjaxAuthentication.aspx",
type: "POST",
data: {
Name: p.name,
Email: p.email,
AccTocken: p.id,
OauthType: r.network
},
success: function (data) {
location.href = "/Default.aspx";
},
error: function (request, status, error) {
alert("getAuthentication code:" + request.status + "\n" + "message:" + request.responseText + "\n" + "error:" + error);
}
});
}else {
$("#hidNetwork").val(r.network);
}
});
});
hello.init({
google: CLIENT_IDS.google,
facebook: CLIENT_IDS.facebook,
twitter: CLIENT_IDS.twitter
}, {
scope: 'email',
redirect_uri: 'http://www.gamedict.com/'
});
</script>
this Code is work.
this is view page
<button onclick="GameShare('google');">Share Google</button>
<button onclick="GameShare('facebook');">Share Facebook</button>
<script type="text/javascript">
$(document).ready(function () {
var isBoardGame = $("#<%=IsBoardGame.ClientID%>").val();
if (isBoardGame == "true") {
$(".BoardNotUse").hide();
}
});
function GameShare(network) {
hello(network).login({ scope: 'publish' }, function () {
alert(network);
// Post the contents of the form
hello.api(network + ':/me/share', 'get', { link: "<%=string.Format("http://{0}{1}",HttpContext.Current.Request.Url.Authority, HttpContext.Current.Request.RawUrl) %>" }, function (r) {
if (!r || r.error) {
alert("Whoops! " + r.error.message);
}
else {
alert("Your message has been published to " + network);
}
});
});
}
</script>
this page "share" is not work.
My site url: http://www.gamedict.com/PC/test11
That page bottom has button for share.
What is my mistake?

Given hello.api( path, method, data ) the value of method needs to be "post" - not "get"

Related

Script not works (ASP.NET MVC)

I have script for recording video
Here is code of it
var fileName;
stop.onclick = function () {
record.disabled = false;
stop.disabled = true;
window.onbeforeunload = null; //Solve trouble with deleting video
preview.src = '';
fileName = Math.round(Math.random() * 99999999) + 99999999;
console.log(fileName);
var full_url = document.URL; // Get current url
var url_array = full_url.split('/') // Split the string into an array with / as separator
var id = url_array[url_array.length - 1]; // Get the last part of the array (-1)
function save() {
$.ajax({
type: 'Post',
dataType: 'Json',
data: {
link: fileName,
id: id,
},
url: '#Url.Action("LinkWriter", "Interwier")',
success: function (da) {
if (da.Result === "Success") {
alert("lol");
} else {
alert('Error' + da.Message);
}
},
error: function (da) {
alert('Error');
}
});
}
I try to get url with this row var id = url_array[url_array.length - 1]; // Get the last part of the array (-1)
and with this code write to table filename
$.ajax({
type: 'Post',
dataType: 'Json',
data: {
link: fileName,
id: id,
},
url: '#Url.Action("LinkWriter", "Interwier")',
success: function (da) {
if (da.Result === "Success") {
alert("lol");
} else {
alert('Error' + da.Message);
}
},
error: function (da) {
alert('Error');
}
});
}
but it not works.
There is my Action method for it
[HttpPost]
public ActionResult LinkWriter(string link, int id) {
Link link_ = new Link
{
Link1 = link,
Interwier_Id = id,
};
db.Link.Add(link_);
db.SaveChanges();
return View();
}
But it not works. Where is my mistake?
UPDATE
As I understood not works this
function save() {
$.ajax({
type: 'Post',
dataType: 'Json',
data: {
link: fileName,
id: id,
},
url: '#Url.Action("LinkWriter", "Interwier")',
success: function (da) {
if (da.Result === "Success") {
alert("lol");
} else {
alert('Error' + da.Message);
}
},
error: function (da) {
alert('Error');
}
});
}

Autocomplete Web Service in ASP.Net web forms

I have a web service for multiple item selection, its working fine but i am getting Undefined data. anyone can tell me solution for it. I am attaching my error screenshot too with this post, please see them below.
Web Service JSON Code
<script type="text/javascript">
$(document).ready(function () {
SearchText();
});
function SearchText() {
$("[id*=ctl00_ContentMain_TextBoxSkills]").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: '<%=ResolveUrl("WebServiceSkills.asmx/GetAutoCompleteData")%>',
data: "{'skill':'" + extractLast(request.term) + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("No Result Found");
}
});
},
focus: function () {
// prevent value inserted on focus
return false;
},
select: function (event, ui) {
var terms = split(this.value);
// remove the current input
terms.pop();
// add the selected item
terms.push(ui.item.value);
// add placeholder to get the comma-and-space at the end
terms.push("");
this.value = terms.join(", ");
return false;
}
});
$("#ctl00_ContentMain_TextBoxSkills").bind("keydown", function (event) {
if (event.keyCode === $.ui.keyCode.TAB &&
$(this).data("autocomplete").menu.active) {
event.preventDefault();
}
})
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}
}
</script>
Web Service:
[WebMethod]
public List<UserRegistration> GetAutoCompleteData(string skill)
{
List<UserRegistration> list = new List<UserRegistration>();
UserRegistrationHelper userRegistrationHelper = new UserRegistrationHelper();
using (DataTable dataTable = userRegistrationHelper.GetSkillsList(skill))
{
if (CommonFunctions.ValidateDataTable(dataTable))
{
foreach (DataRow dr in dataTable.Rows)
{
var SkillsList = new UserRegistration
{
SkillId = Convert.ToInt32(dr["SkillId"].ToString()),
Skills=dr["SkillName"].ToString()
};
list.Add(SkillsList);
}
}
}
return list;
}
Screenshot here:
I got answer for it:
1: Change SQL Query:
select concat('[', STUFF
(
(
SELECT top 15 '","'+ CAST(skillname AS VARCHAR(MAX))
from DNH_Master_Skills where SkillName LIKE '%' + #SkillName + '%'
FOR XMl PATH('')
),1,2,''
),'"]')
2: Change JSON Code:
From: response(data.d); TO: response(Array.parse(data.d));
Now its working feeling happy.

JQuery AutoComplete with ASP.Net

Below is my JavaScript
<script>
$(function () {
function log(message) {
$("<div/>").text(message).prependTo("#log");
$("#log").attr("scrollTop", 0);
}
$("#city").autocomplete({
source: function (request, response) {
$.ajax({
url: "getpostcodes.aspx",
dataType: "jsonp",
data: {
like: request.term
},
success: function (data) {
response($.map(data.RegionList, function (item) {
return {
label: item.Detail,
value: item.Detail
}
}));
}
});
},
minLength: 2,
select: function (event, ui) {
log(ui.item ?
"Selected: " + ui.item.label :
"Nothing selected, input was " + this.value);
},
open: function () {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function () {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
});
});
</script>
And below is my JSON Returned by the server
{"RegionList":[{"Detail":"2250, GOSFORD"}]}
But my auto complete doesn't show up the result? am i doing anything wrong?
What is the HTTP Status code response? I had problemas sometimes because I received the answer, but the status code was 500

why jquery can't return string/text?

default.aspx
<button id="getGrouper">GetGroupers</button>
<script type="text/javascript">
$(document).ready(function () {
$("#getGrouper").click(function () {
$.ajax({
type: "post",
url: "Groupers.aspx/groupers",
data: "{pid:25}",
dataType: "text",
success: function (data) { alert(data); },
error: function (err) { alert("err:" + err); }
});
return false;
});
});
</script>
groupers.aspx.cs
[WebMethod]
public static string groupers(
int project_id)
{
string employees = "";
foreach (string s in ids.Split(','))
{
u = user.getUserbyUid(Convert.ToInt32(s));
employees += "<a class=\"reply_notify_delete\" href =showuser.aspx?uid=" + u.Uid + "&pid=" + p.Pid + ">" + u.userName + "</a> ";
}
return employees;
}
want to get groupers by a project_id
i want to get string type ,then append it, but i debug the code , it doesn't work , no response , and i set breakpoin , it doesn't go into "groupers" static Method , why ?
Where you have
"{pid:25}",
dataType: "text",
change it to
'{"project_id":25}',
dataType: "json",

Jquery AutoComplete Load Problem

Not Work
Jquery Code:
$('[id$=Name]').autocomplete('CallBack.aspx',{formatItem: function(item){return item.Name;}}).result(function(event, item) {
location.href = item.AGE;
});
Json:
var data = [{NAME:"John",AGE:"57"}];
Work
Jquery Code:
var data = [{NAME:"John",AGE:"57"}];
$('[id$=Name]').autocomplete(data,{formatItem: function(item){return item.Name;}}).result(function(event, item) {
location.href = item.AGE;
});
alt text http://img11.imageshack.us/img11/119/38235621.jpg
Help me pls how its make ? callback.aspx return json not work
Try changing your data to this:
var data = [{id:"John",value:"57"}];
EDIT
Here's a sample of what I think you're trying to do:
var data = [{NAME:"John",AGE:"57"}];
$('[id$=Name]').autocomplete('CallBack.aspx', {
formatItem: function(item) {
return item.NAME;
}}).result(function(event, item) {
location.href = 'somepage.aspx?age=' + item.AGE;
});
Basically you needed to capitalise return item.Name to return item.NAME.
Try This
<script type="text/javascript">
$(document).ready(function () {
$("#TextboxId").autocomplete({
source: function (request, response) {
$.ajax({
url: "URL",
type: "POST",
dataType: "json",
data: { ids: idstopass },
success: function (retrieveddata) {
alert(retrieveddata);
var dData = JSON.parse(retrieveddata);
alert(dData.Name);
},
error: function (request, status, error) {
console.log("Error! " + request.responseText);
}
})
},
});
})
</script>

Resources