Domino Access Service - Form property not submitted - json

I have copied the routine how to perform a post action towards Domino Access Service inspired by the example described here:
http://www.browniesblog.com/A55CBC/blog.nsf/dx/09042013111234MBRF6E.htm?opendocument
The problem is that all properties get submitted except the Form property. Why is this?
$(document).ready(function() {
$(".btnRegister").click(function(e) {
var firstName = $(".firstName").val();
var lastName = $(".lastName").val();
var email = $(".email").val();
var password = $(".wannebepassword").val();
var newName = $(".firstName").val() + " " + $(".lastName").val();
if (newName !== " ") {
var newPersonObj = {Form: "Person", FirstName: firstName, LastName: lastName, FullName: newName, InternetAddress: email, HTTPPassword: password, Form: "Person"};
$.ajax({
url: 'http://server/names.nsf/api/data/documents',
type: 'POST',
data: JSON.stringify(newPersonObj),
dataType: 'xml',
accepts: {
xml: 'text/xml',
text: 'text/plain'
},
contentType: "application/json"
}).done(function(data, textStatus, jqXHR) {
var newPersonLocation = jqXHR.getResponseHeader("Location");
$("#formResponse").html('Registration successfull. Location = ' + newPersonLocation + '<br>' + $("#myConsole").html());
}).fail(function(jqXHR, textStatus, errorThrown) {
alert("Registration has failed:" + errorThrown );
console.log('Registration has failed.');
});
}
else {
alert("Please enter a name");
}
return false;
});
});

Try to add a field in your form with the name (I suggest also HTML Tag: ID) FORM, editable with default value:
Form
NB editable is not mandatory, Computed is also possible.

Related

Autocomplete postal code and place name with Ajax and Geonames

I would like to have a autocomplete for a textfield (tf_place), where you start to type the place name (of a German city) and it fills in the complete city name. As source I would like to use GeoNames. I already created a new user account and confirmed it.
$('[data-name="tf_place"]').autocomplete({
source: function (request, response) {
$.ajax({
url: "http://api.geonames.org/postalCodeSearchJSON",
dataType: "jsonp",
data: {
featureClass: "P",
maxRows: 10,
country: "DE",
placename_startsWith: request.term,
username: "myUser"
},
success: function (data) {
response($.map(data.postalCodes, function (item) {
return {
label: item.postalCode + "-" + item.placeName,
value: item.postalCode + "-" + item.placeName
}
}));
}
});
},
});
What's wrong?
Edit: I tried the complete URL:
http://api.geonames.org/postalCodeSearchJSON?featureClass=P&maxRows=10&country=DE&placename_startsWith=Be&username=myUser
It works! (to make it work for you, you need to replace myUser with your own username)
So why doesn't my code work?

How to pass a variable in button id and then send that id to ajax data?

I am passing id of the product to button id and then through Ajax data, I'm sending that product id to the controller
for(var i=0;i<productsJSON.length;i++)
{
var td5 = document.createElement('td');
td5.innerHTML = "<br><button type='button' id="+product.id+"onclick='Addtocart() ' >Add To Cart</button><br>";
}
function Addtocart() {
var quantity = document.getElementsByName("quantity").item(0).value;
$.ajax({
type: "POST",
data: 'pid=' + this.id + '&quantity=' + quantity,
url: "ProductController",
success: function(content) {
console.log(content);
alert('done');
}
});
}
You have to use a JSON object.
Here I set data from an HTML form using the GET method.
$.ajax(
{
type: "GET",
data: $("#form").serialize(),
url: "url",
success: function(data)
{
# Code
},
error: function()
{
# Code
}
}
);

Database Not Showing Data in Json Ajax

This is my view file Book.cshtml script section. The problem coming is that it not fetching my data from my database.
Instead it is giving a error:
alert("Failed! Please try again.")
If I truncate the data from the database it shows ONLY the heading "BOOK ID" "BOOK NAME" "BOOK SERIAL NUMBER" "BOOK AUTHER" "BOOK PUBLISHER NAME"
$(document).ready(function () {
// This is for Get All Data
$("#btnAllBook").click(function () {
$.ajax({
url: "#Url.Action("GetAllBook","Books")",
data: "",
type: "GET",
dataType: "json",
success: function (data)
{
loadData(data);
},
error: function () {
alert("Failed! Please try again.");
}
});
});
// this will use for Get Data based on parameter
$("#btnSearch").click(function () {
$.ajax({
url: "#Url.Action("GetBookWithParameter", "Books")",
data: { prefix: $('#txtSearch').val() },
type: "GET",
dataType: "json",
success: function (data) {
loadData(data);
},
error: function () {
alert("Failed! Please try again.");
}
});
});
function loadData(data) {
// Here we will format & load/show data
var tab = $('<table class="myTable"></table>');
var thead = $('<thead></thead>');
thead.append('<th>Book ID</th>');
thead.append('<th>Book Name</th>');
thead.append('<th>Book Serial Number</th>');
thead.append('<th>Book Auther</th>');
thead.append('<th>Book Publisher</th>');
tab.append(thead);
$.each(data, function (i, val) {
// Append database data here
var trow = $('<tr></tr>');
trow.append('<td>' + val.BookID + '</td>');
trow.append('<td>' + val.BookName + '</td>');
trow.append('<td>' + val.BookSerialNumber + '</td>');
trow.append('<td>' + val.BookAuther + '</td>');
trow.append('<td>' + val.BookPublisher + '</td>');
tab.append(trow);
});
$("tr:odd", tab).css('background-color', '#C4C4C4');
$("#UpdatePanel").html(tab);
};
});
Looking into the documentation on http://api.jquery.com/jquery.ajax/, the callback error is called because the request failed. Then, I suggest you to check if the url #Url.Action("GetAllBook","Books") is returning the right string of the url, maybe you are trying to request in a url that doesn't exists.
Another point, being about a GET request, I suggest you to check opening in a browser if this URL that you are trying to return data, is returning the JSON data expected as you need to append to the HTML.

Knockout applyBindings does not applyBinding

I have just started to use knockout.js and am stuck when trying to show JSON data.
My HTML is
<p>Dealer Location: <input id="dealerlocation" data-bind="value: DealerLocation" /></p>
<p>Contact Report Date: <input id="crdate" data-bind="value: CRDate" /></p>
My Script Block is
function viewAction() {
var self = this;
self.DealerLocation = ko.observable("");
self.CRDate = ko.observable("");
};
var viewActionModel = new viewAction();
function GetActionByID() {
$.ajax({
type: "POST",
url: "/ws/someservice.asmx/GetAction",
data: "{pacid: '" + $('input[id$=hidActionID]').val() + "'}",
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function (response) {
var action = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
$.each(action, function (index, axn) {
viewActionModel.DealerLocation = axn.DealerLocation;
viewActionModel.CRDate = axn.CRDate;
});
}
});
}
$(document).ready(function () {
GetActionByID();
//alert(viewActionModel.DealerLocation);
ko.applyBindings(viewActionModel);
});
Note: If I uncomment alert then applyBinding works otherwise it does not.
What is missing here???
Ragards.
This is a wrong way to assign observables.
viewActionModel.DealerLocation = axn.DealerLocation;
viewActionModel.CRDate = axn.CRDate;
Do it like this.
viewActionModel.DealerLocation(axn.DealerLocation);
viewActionModel.CRDate(axn.CRDate);
By doing what you do now you are replacing observables with regular variable. It was working with alert because this replacement took place before binding and knockout just picked up your regular variables. Read more about observables.

Unable to recieve JSON from Webmethod using $.getJSON or Ajax call

I have some JSON objects that I want to process on Client Side, but My WebMethod that I specified does not want to fire.
Here is the Ajax and GetJson methods i used in my Client Side Script:
GetSJON
$(document).ready(function() {
$(document).ready(function() {
//attach a jQuery live event to the button
$('#getdata').live('click', function() {
$.getJSON('/Members_Only/StockMovement/WebForm1.aspx/StockPlacementOptions', function(data) {
//alert(data); //uncomment this for debug
// alert(data.item1 + " " + data.item2 + " " + data.item3); //further debug
$('#showdata').html("<p>item1=" + data.item1 + " item2=" + data.item2 + " item3=" + data.item3 + "</p>");
});
});
});
Here is the Ajax
$(document).ready(function () {
$.ajax({
type: "POST",
url: "/Members_Only/StockMovement/WebForm1.aspx/StockPlacementOptions",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{}",
success: function (res) {
$('#Results').append(CreateTableView(res)).fadeIn();
}
});
});
Both of these Methods Call StockPlacementOptions which is my WebMethod that look like this:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json,
UseHttpGet = true, XmlSerializeString = false)]
public static List<StockReturnMethod> StockPlacementOptions()
{
scmEntitiesPrimaryCon entities = new scmEntitiesPrimaryCon();
var binOptions = (from avail in entities.ProductAvailibleBins(1, 2)
select new StockReturnMethod() { LotID = (int)avail.LotID, LotName = avail.LotName, AreaID = (int)avail.AreaID, AreaName = avail.AreaName, BinID = (int)avail.BinID, BinName = avail.BinName }).ToList();
return binOptions;
}
If I can just get the JSON web Method to fire on $(document).ready event, I will be able to process and work with the data from there. I have also tried looking at a diffrent jQuery library like KnockoutJS with it's data processing capability, also no luck.
I am using ASP Webforms on Framework 4 with Html5 Markup.
Any advice will be greatly appreciated.
Why are you using two document.ready() handlers at your client side getJson and ajax
$(document).ready(function() { // <-------you can remove this handler
$(document).ready(function() {
$('#getdata').live('click', function() {
$.getJSON('/Members_Only/StockMovement/WebForm1.aspx/StockPlacementOptions', function(data) {
//alert(data); //uncomment this for debug
// alert(data.item1 + " " + data.item2 + " " + data.item3); //further debug
$('#showdata').html("<p>item1=" + data.item1 + " item2=" + data.item2 + " item3=" + data.item3 + "</p>");
});
});
}); // <-------you can remove this handler
although i am not sure this could be the issue but try this one if this helps.
I got it fixed by using a combination of KnockoutJS and ajax.
By utilizing the knockoutJS mapping model, I am able to manipulate the returned JSON anyway i want :)
Here is my Jquery that does the Mapping and obtains JSON from server.
<script type="text/javascript">
//Declareing Viewmodel For KnockoutJS
var viewModel;
//Using Mapping Plugin for Knockout JS
function bindModel(data) {
viewModel = ko.mapping.fromJS(data);
console.log(viewModel);
ko.applyBindings(viewModel);
}
//Onload ObtainJSON
$(document).ready(function () {
$.ajax({
url: "WebForm1.aspx/StockPlacementOptions",
// Current Page, Method
data: {},
// parameter map as JSON
type: "POST",
// data has to be POSTed
contentType: "application/json",
// posting JSON content
dataType: "JSON",
// type of data is JSON (must be upper case!)
timeout: 10000,
// AJAX timeout
success: function (result) {
bindModel(result);
},
error: function (xhr, status) {
alert(status + " - " + xhr.responseText);
}
});
});
</script>
I also changed the Webmethod slightly to obtain the result i wanted:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static List<StockReturnMethod> StockPlacementOptions()
{
scmEntitiesPrimaryCon entities = new scmEntitiesPrimaryCon();
var binOptions = (from avail in entities.ProductAvailibleBins(1, 2)
select new StockReturnMethod() { LotID = (int)avail.LotID, LotName = avail.LotName, AreaID = (int)avail.AreaID, AreaName = avail.AreaName, BinID = (int)avail.BinID, BinName = avail.BinName }).ToList();
return binOptions;
}
And That's it :D
Thanks for all the help