I made an application based on phone gap 2.9.1 android application with local database
with transaction and create query. but now i want to make remote database for this application so that i can use it from anywhere with same database. Can anyone help me? please..
Thanks..
Make a webservice. connect through it using ajax and parse json
Edited
I tried something like this (this is not web service though)
below is made from ASP.Net
[AllowCrossSiteJson]
public JsonResult AddPerson(Person person)
{
//Get Data here
return Json(*put something here*);
}
and called it in my javascript
function saveData(person) {
var json = $.toJSON(person); //converts person object to json
$.ajax({
url: "http://somedomain.com/Ajax/AddPerson",
type: 'POST',
dataType: 'json',
data: json,
contentType: 'application/json; charset=utf-8',
success: function (data) {
alert("ok");
}
});
}
Edited Part 2
You can do the same in PHP
Related
i am try to get data from web service ,, the web service is
http://www.webservicex.net/country.asmx?op=GetCountries
i am use the suds.js
how to get the data from the web service or how to call web service without send parameters or please help me in anything
$.ajax({
url: "http://www.webservicex.net/country.asmx?op=GetCountries",
type: 'POST',
dataType: 'xml',
success: function (xmldata, textStatus, XMLHttpRequest) {
//Do your thing! For instance:
console.log(xmldata);
}
});
I'm doing a project in Jquery Mobiles and need an webservice. Normally in android we have the http connection and we got the response as xml/json etc.. We parse the data and processed to the view. Here,In case of jquery , facing problem to solve the issue.. I read that ajax call is using for the webservices.
Sample code
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "some url",
data: "{}",
dataType: "json",
success: function (msg) {
alert(msg);
//$("#resultLog").html(msg);
}
});
Also,I refer the google api_Place Search, the service for this is entirely different
RefernceLink Click HERE!
Does anyone suggest the proper way to implement the webservice to interact with my server and retrieve the json response?
Thanks in Advance!
I need your help with a big doubt.
Question: As I can create JSON file (with data) from JS code?
The reason is which I need use JSONP, and I wanna take that data from other domain (i.e. http://www.example.com/data/clients.json?callback=?), but this data are storage in a DB (WebSQL) and I need which that data is written in the json file (i.e. clients.json)
Please I need your help because three days ago I try do this, but I don't find yet the answer.
P.S.: Sorry for my english, not is my native language.
EDIT
Sorry my question is confused. I try again but for steps.
I need to write a JSON file with data or records from a DB (WebSQL). Actually my functions are working well (add record, update record, delete), but I need to put that data in a json file because, I'll use the next code for get the data from other domain.
(function($) {
var url = 'http://www.example.com/scripts/clients.json?callback=?';
$.ajax({
type: 'GET',
url: url,
async: false,
jsonpCallback: 'jsonCallback',
contentType: "application/json",
dataType: 'jsonp',
success: function(json) {
console.dir(json.sites);
},
error: function(e) {
console.log(e.message);
}
});
})(jQuery);
I have an asp.net webforms website and a wcf service. I use jQuery to perform my AJAX operations to/from the WCF service like so:
$.ajax({
type: "POST",
url: "192.168.1.24/ServiceMain.svc/" + serviceName,
dataType: "json",
contentType: "application/json; charset=utf-8",
data: "{}",
cache: true,
success: function (json)
{
//Success operation here
},
error: function ()
{
//Error operation here
}
});
All is fine right now. However, I want to be able to do a testing and production environment, both of which will be hosted on a different server with different IP Addresses.
Clearly, hard-coding the URL to point to the correct WCF service will become a tedious problem if left unchecked. Therefore, I was wondering what was the best approach in retrieving the WCF Service's URL. I thought about using the web.config file with something like the following:
<%=ConfigurationManager.AppSettings("SomeWCFKey")%>
However, I am not sure how to correctly reference the address in my web.config file:
<endpoint address="http://192.168.1.24/ServiceMain.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IServiceMain"
contract="ServiceMain.IServiceMain"
name="BasicHttpBinding_IServiceMain" />
Any help would be appreciated, thanks.
Hi i think you are actully want to read endpoint address that you can get by this code
private List<string> GetEndpoints()
{
var endpointList = new List<string>();
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var serviceModel = ServiceModelSectionGroup.GetSectionGroup(config);
foreach (ChannelEndpointElement endpoint in serviceModel.Client.Endpoints)
{
endpointList.Add(endpoint.Address.ToString());
}
return endpointList;
}
Here is pont that descirpt mroe in detail : Getting WCF Bindings and Behaviors from any config source
this might also help you : Programmatically enumerate WCF endpoints defined in app.config
All the examples of json I can find online only show how to submit json arrays w/ the jquery command $.ajax(). I'm submitting some data from a custom user control as a json array. I was wondering if it's possible to submit a json array as a regular post request to the server (like a normal form) so the browser renders the page returned.
Controller:
[JsonFilter(Param = "record", JsonDataType = typeof(TitleViewModel))]
public ActionResult SaveTitle(TitleViewModel record)
{
// save the title.
return RedirectToAction("Index", new { titleId = tid });
}
Javascript:
function SaveTitle() {
var titledata = GetData();
$.ajax({
url: "/Listing/SaveTitle",
type: "POST",
data: titledata,
contentType: "application/json; charset=utf-8",
});
}
Which is called from a save button. Everything works fine but the browser stays on the page after submitting. I was thinking of returning some kind of custom xml from the server and do javascript redirect but it seems like a very hacky way of doing things. Any help would be greatly appreciated.
This is an old question but this might be useful for anyone finding it --
You could return a JsonResult with your new titleId from the web page
public ActionResult SaveTitle(TitleViewModel record) {
string tId = //save the title
return Json(tId)
}
and then on your ajax request add a success function:
function SaveTitle() {
var titledata = GetData();
$.ajax({
url: "/Listing/SaveTitle",
type: "POST",
data: titledata,
contentType: "application/json; charset=utf-8",
success: function(data) { window.location = "/Listing/Index?titleId=" + data; }
});
}
That would redirect the page after a successful ajax request.
I just saw that you mentioned this at the end of your post but I think it is an easy and quick way of getting around the issue.
Phil Haack has a nice post discussing this scenario and shows the usage of a custom value provider instead of an action filter.
I don't understand why you would want to post Json if you're wanting to do a full page post. Why not just post normal form variables from the Html form element?