I have the following querystring (where kvks is dynamic):
http://api.openkvk.nl/json/SELECT bedrijfsnaam FROM kvk WHERE kvks = 27312152 LIMIT 1;
If you execute this querystring, it will return json data. What is the best approach to handle this? I tried it in this way, but nothing alerts
url.append("http://api.openkvk.nl/json/SELECT bedrijfsnaam FROM kvk WHERE kvks = ");
url.append(Dossierno);
url.append(" LIMIT 1");
$.get(url, function (data) {
alert(data); });
Or should I handle this in a separate aspx page?
$.get('getaddress.aspx', { sDos开发者_如何学编程sierno : Dossierno} function (data) {
alert(data); });
If yes, how can I send a querystring and return the json object on the getaddress aspx page?
That's not query string that you have. It's part of the uri and ASP.NET won't probably allow it. You may try the following:
$.get(
'http://api.openkvk.nl/json',
{ q: 'SELECT bedrijfsnaam FROM kvk WHERE kvks = ' + Dossierno + ' LIMIT 1' },
function (data) {
alert(data);
}
);
where the corresponding server side script will read the q
query string parameter.
Also I hope you are aware of the implications in terms of security of having a server side script which accepts what seems to be a SQL query and executes it against a relational database. And last but not least don't forget about the same origin policy restriction and make sure that this script is hosted on http://api.openkvk.nl
if you intend to send AJAX requests to it.
- Do not pass entire SQL Queries in query strings, as it allows for malicious code to reach your database.
- string variables do not have an append method, so check if that really works as expected (alert the url to see if it is what you expect it to be)
- You are not allowed to make requests from a different domain (if you page is not at api.openkvk.nl), only JSONP is allowed cross-domain. Check same-origin-policy.
精彩评论