write JSON data in sql - javascript

Being a newbie and working on a web application i am stuck at passing a JSON object in Javascript file to a SQL database. I have no clue on how to proceed further. I have created a SQL table with this addon of mozilla https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/
Any suggestions on how to perform this?

If you want to pass JSON object to database then you can use "$.ajax".
Sample Code:
$.ajax({
type: "POST",
url: "mypage.aspx/mystaticmethod",
data: "{'fistcolumn':'firstvalue','secondcolumn':'secondvalue'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
});
}
});
At:
data: "{'fistcolumn':'firstvalue','secondcolumn':'secondvalue'}",
you can directly send your JSON object and at code behind you will get all values.
protected static void mystaticmethod(string firstcolumn, string secondcolumn)

Related

Posting raw data to a WebAPI using JQuery and AJAX

I am trying to work out how to post raw data to a webAPI using JQuery and Ajax, but I cannot seem to get the data to be sent across.
The endpoint works in Postman:
Here is my rather simple JQuery:
$.ajax({type: "POST", url: myUrl, data: ["21924"]});
What am I missing? This is not my usual area so I've had a good look through other questions, but non seem to quite fit! How do I recreate this Postman call via JQuery and Ajax?
Thanks.
Try specifying the data type and stringifying your data, like this:
$.ajax({
type: "POST",
url: myUrl,
data: JSON.stringify(["21924"]),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data){console.log(data);},
failure: function(errMsg) {console.log(errMsg);}
});

Issue in save values by Json (WCF)

I have the following Code in Json :
$.ajax({
type: "POST",
data: JSON.stringify(params),
contentType: "application/json; charset=utf-8",
url: AppCOJS.getBaseURL() + '/hcis/license-services/SE.TCC.CLU.Services.Transactional.ServiceManagementRequestInfoDetails.svc/SaveCustomerClearanceInformation',
dataType: "json",
async: true,
complete: SaveCustomerClearanceInformationCompleted
});
That code for adding values to table in DataBase sql server ,I submitte the request and I see the result data which is returned by WCF service in google chrome debugging window .
But when i go to the table i didn't see any values added to it ?
When I execute the request by Console Application ,It is working fine and the values are added to the table .
What is the problem ?

jQuery Ajax POST JSON issue

I'm trying to pass a JavaScript array into a PHP script to then be put into a database but I'm having issues. I have used JSON.stringify on the array before sending. The request seems to work in that when stepping through the code debugging the php page is called but no data is passed into the POST global. I'm sure its something amateurish that I've missed but I'm struggling. This is the code:-
$.ajax({
type: "POST",
datatype: "json",
url: "processdraw.php",
data: {
json: pDrawnTeams
},
contentType: "application/json; charset=utf-8",
success: alert('worked')
})
If you are not getting any error in your javascript, make sure that you are getting that parameter like this in your php target file:
$myJSON = $_POST['json']; // ['parameter name']
after that you will need to decode that json
$myData = json_decode($myJSON, true) // true is for retrieving as an array

Google calendar returns not a valid json file

We are making a website with AngularJS. We need the google calendar events.
I try to load the data from a Google Calandar.
here you can find the json file: http://www.google.com/calendar/feeds/nmk97b3l07ncb9f9h5ap5ffo2c#group.calendar.google.com/public/full?alt=json-in-script&callback=insertAgenda&orderby=starttime&max-results=15&singleevents=true&sortorder=ascending&futureevents=true
But Angulair does not recognize it as a json file.
Is there a way to get this as json file?
insertAgenda is the jsonp-callback-parameter.
Try this:
var url = 'http://www.google.com/calendar/feeds/nmk97b3l07ncb9f9h5ap5ffo2c#group.calendar.google.com/public/full?alt=json-in-script&callback=insertAgenda&orderby=starttime&max-results=15&singleevents=true&sortorder=ascending&futureevents=true';
$.ajax({
type: 'GET',
url: url,
async: false,
jsonpCallback: 'insertAgenda', //The callback parameter in Google Calendar response
contentType: "application/json",
dataType: 'jsonp',
success: function(json) {
console.dir(json);
}
});
DEMO

Can I bind asp.net dropdownlist using javascript/jquery?

Can I bind asp.net dropdownlist using javascript/jquery? I get the data from jquery ajax from a web method so I want to avoid postback at this point. But I still want to do postback and save all the data using server side code (i.e. I still be able to do this dropdownlist1.selecteditem.text) after binding it using clientscripts.
Is it possible and can someone explain me how it can be done?
Thanks,
Use Json ajax
Syntax:
$.ajax({
dataType: "json",
url: url,
data: data,
success: success
});
See simple example for json:
<script type="text/javascript">
$(document).ready(function () {
var msgbox = $("#status");
$("#Button1").click(function () {
$.ajax({
type: "POST",
//Page Name (in which the method should be called) and method name
url: "BeginJson.aspx/CheckDateTime",
// If you want to pass parameter or data to server side function you can try line
// data: "{}",
//else If you don't want to pass any value to server side function leave the data to blank line below
data: "{'args':'Somnath'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
//Got the response from server and render to the client
msgbox.html(msg.d);
}
});
});
});

Categories

Resources