|
From what I can tell, this appears to be a server-side problem. If I type the URL into a browser, I get back the same format I posted earler. It's clearly not JSON.
Here's my WebAPIConfig:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Formatters.Remove(config.Formatters.XmlFormatter);
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
}
}
Other than this, I'm not reallt sure what else to look for. I'm open to ideas.
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
Richard Deeming wrote: Are your classes marked as [Serializable] ? You may need to add [DataContract] to the class and [DataMember] to the properties.
Yes, I had the [Serializable] attribute, but not the others. I look at that twice and just didn't see it. Too many late nights
It seems to work OK now. Thank you for all your help.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I'm trying to make an add-on for Firefox that will store some values which will be used later on in an contextMenus.
Getting the value and setting a new one in options_ui works just fine. The problem is when I try to get the value by using the new contextMenu I am adding in background.js. The new contextMenu it is added, the window for saving the file appers, but the value from storage returns undefined. Can anyone help me with this, point me where I'm doing something wrong?
I am setting a new value before using the contextMenu.
background.js
var gettingValue = browser.storage.sync.get("number");
gettingValue.then(item =>{
browser.contextMenus.create({
id: "save-image",
title: "Save image",
contexts: ["image"],
});
browser.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "save-image") {
let name = "Initial";
if(item) {
name = item.number;
} else {
name = "Number not found";
}
browser.downloads.download({
url : info.srcUrl,
filename : name + ".jpg",
saveAs : true
});
}
});
});
options.js
function saveOptions(e) {
e.preventDefault();
browser.storage.sync.set({
number: document.querySelector("#newNumber").value
});
}
function restoreOptions() {
let getting = browser.storage.sync.get("number");
getting.then(setCurrentChoice, onError);
function setCurrentChoice(result) {
document.querySelector("#newNumber").value = result.number || "No number was set";
}
function onError(error) {
console.log(`Error: ${error}`);
}
}
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);
options.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<form>
<label>Number input: <input type="text" id="newNumber" ></label>
<button type="submit">Save</button>
</form>
<script src="options.js"></script>
</body>
</html>
Permissions in manifest
"permissions": [
"contextMenus",
"downloads",
"storage"
],
modified 4-Nov-20 9:02am.
|
|
|
|
|
Solution:
browser.contextMenus.create({
id: "save-image",
title: "Save image",
contexts: ["image"],
});
browser.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "save-image") {
var gettingValue = browser.storage.sync.get("number");
gettingValue.then(item =>{
let name = "Initial";
if(item) {
name = item.number;
} else {
name = "Number not found";
}
browser.downloads.download({
url : info.srcUrl,
filename : name + ".jpg",
saveAs : true
});
});
}
});
|
|
|
|
|
Could anybody help me to explain this block code, i knew that is callback hell and try to imagine short and simple but i can not
Thanks alot
--------------------------
function getAll() {
getName("Hoa",function(){
getName("Moc",function(){
getName("Lan",function(){
getName("Duy",function(){
})
})
})
})
}
function getName(name, cb){
setTimeout(
function() {
console.log(name);
cb();
}, 1000
)
}
getAll();
|
|
|
|
|
Start by using Promises:
Using Promises - JavaScript | MDN[^]
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
function getName(name) {
return wait(1000).then(() => console.log(name));
}
function getAll(){
getName("Hoa")
.then(() => getName("Moc"))
.then(() => getName("Lan"))
.then(() => getName("Duy"));
} Demo[^]
Support is pretty good in everything except Internet Explorer.
If you want to make it even cleaner, consider using an async function:
async function - JavaScript | MDN[^]
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
async function getName(name) {
await wait(1000);
console.log(name);
}
async function getAll(){
await getName("Hoa");
await getName("Moc");
await getName("Lan");
await getName("Duy");
} Demo[^]
Again, support is pretty good for everything except Internet Explorer.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Dear all
could anybody help me with image in the red frame. When i remove 2 images, the image work perfectly with perfectly circle, but when I add more two pictures, the circle transform into the oval.
Could anybody help me to keep remain the circle, if i add more pictures, it can be hidden or appear half or quarter is fine with me.
here is my code: https://jsfiddle.net/n6fb9xtr
thanks alot
|
|
|
|
|
Hi all
Could anybody tell me why this code block css:
.img-bcg {
height: calc(100vh -77.8px);
background: url("https://unsplash.com/photos/Q0mDOn9gWk8") center/cover no-repeat;
} not working in my project below.
https://jsfiddle.net/hu5s3c7o/
thank alot
|
|
|
|
|
Two problems:
- Your height property is invalid. You need a space between the
- and the 77.8px . - You've specified the URL of the HTML page containing the image, not the image itself. HTML pages cannot be used as background images.
Change your style to:
.img-bcg {
height: calc(100vh - 77.8px);
background: url("https://images.unsplash.com/photo-1510662179966-f3e62f0fb4fe?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80") center/cover no-repeat;
} Updated demo[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
It works perfectly,
thanks alot
|
|
|
|
|
Hello:
Windows 10 workstation
Apache 2.4
PHP 7.2.
I've installed Apache and PHP on a Windows 10 workstation and everything (including PHP) works beautifully. But when I change the documentroot in the http.conf file, Apache stops sending .php files to the PHP engine. Apache opens the .php files in the new directory, but the <?php> code no longer gets parsed and processed by the php engine (php.exe). Apache no longer runs those files through the php module.
Here is what I've changed in the http.conf file:
OLD SETTING:
DocumentRoot "${SRVROOT}/htdocs"
<Directory "${SRVROOT}/htdocs">
NEW SETTING:
DocumentRoot "C:/WWW"
<Directory "C:/WWW">
When I change it back again, PHP works just fine.
I've also tried changing the doc_root setting in php.ini, but that doesn't help. Apache loads the .php page, but never sends it to the php server.
Any thoughts or help?
Thanks!
|
|
|
|
|
Somewhere else in your httpd.conf there will be some configuration that makes PHP work. Search the file for "php" and see what you can find, then check that it isn't in its own <Directory> group or something similar.
If you can't find anything about PHP in the main file, look for Include lines - the httpd.conf can include other files, so you might have one that is specific to PHP.
The php.ini file is read by PHP itself, and it doesn't sound like it is getting that far.
|
|
|
|
|
Thank you for responding. The problem was a minor one. In the fresh install of PHP, the "short_open_tag" in PHP.ini was defaulted to "Off". The phpinfo file in Apache directory opened with "<?php>" and the file in the new directory opened with "<?>", so it didn't parse. I've changed the php.ini file with "short_open_tag = On" and all is well now.
Simple little things can sometimes trip us up.
|
|
|
|
|
This is a newbie question, how do I add color only on top of my web page, the rest should remain white..
|
|
|
|
|
|
When you set a color or background-color style it applies to the items contained in that element.
Your entire page is a <body> element and so if you change the color at that level the entire page is effected. Now if you create an element within the body, like a <div>, you can control it's styles by putting them in that div. It will then not be spread to the entire page.
OK - now the only thing left for you to do. If you want the top of the page to be one color and the rest of the page to not be affected, you can put that div element at the top of the page. Color it. Put text in it. Put images in it. Anything you want.
It's actually extremely common (probably why you want to do it) - becomes a page header, visually.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
I'm creating a RestSharp wrapper class. I'm trying to test it with a simple controller. I'm getting some errors.
RestSharp Wrapper
public class RestSharpProxy
{
#region Private Fields
private RestClient _client;
private RestRequest _request;
#endregion
#region Properties
public ServerInfo ServerInfo { get; private set; }
#endregion
#region CTOR
public RestSharpProxy(ServerInfo serverInfo, string action, Method method = Method.GET)
{
ServerInfo = serverInfo;
_client = new RestClient(serverInfo.ServerURL)
{
Authenticator = new HttpBasicAuthenticator(serverInfo.UserName, serverInfo.Password)
};
_request = new RestRequest(action, method)
{
RequestFormat = RestSharp.DataFormat.Json
};
}
#endregion
#region Public Methods
public void AddParameter(object arg)
{
_request.AddJsonBody(arg);
}
public void AddParameter(string name, object arg)
{
_request.AddParameter(name, arg);
}
public async Task ExecuteAsync()
{
IRestResponse response = await _client.ExecuteAsync(_request, new CancellationToken());
if (response.ResponseStatus != ResponseStatus.Completed ||
response.StatusCode != System.Net.HttpStatusCode.OK)
{
throw new Exception($"API Error: {response.StatusCode} - {response.ErrorMessage}");
}
}
public async Task<T> ExecuteAsync<T>()
{
IRestResponse<T> response = await _client.ExecuteAsync<T>(_request, new CancellationToken());
if (response.ResponseStatus != ResponseStatus.Completed ||
response.StatusCode != System.Net.HttpStatusCode.OK)
{
throw new Exception($"API Error: {response.StatusCode} - {response.Content}");
}
var results = JsonConvert.DeserializeObject<T>(response.Content);
return results;
}
#endregion
}
Controller
public class CustomerController : ApiController
{
[HttpGet]
public List<CustomerEntity> GetAll()
{
var results = new List<CustomerEntity>
{
new CustomerEntity { Id = 1, CustomerName = "John Smith"},
new CustomerEntity { Id = 2, CustomerName = "William Dover"},
};
return results;
}
[HttpGet]
public CustomerEntity Get(int id)
{
return new CustomerEntity { Id = id, CustomerName = "Amber Stone" };
}
[HttpGet]
public int GetAnInt()
{
return 100;
}
[HttpPost]
public void Add([FromBody] CustomerEntity customer)
{
}
[HttpPost]
public void SendSomeString([FromBody] string value)
{
}
[HttpPost]
public void Update([FromBody] CustomerEntity customer)
{
}
[HttpDelete]
public void Delete(int id)
{
}
}
Issues
Any controller method I call that returns something, like all 3 Get methods, work fine. For any methods that return void I get back "No Content". In all cases the RsponseStatus is Completed.
What am I doing wrong here?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Quote: What am I doing wrong here? You are not returning anything from the controller, hence the "No Content" is being shown on the client-side.
If you want to see something, try returning that value from the controller instead. For example, in your Delete method, return a string stating that the object has been deleted.
[HttpDelete]
public string Delete(int id)
{
return $"Object with ID {id} has been deleted.";
} Now, this should return a string value. Similarly, modify other methods as well so they also return a proper response instead of a void telling the browser to not print anything.
With an API, you are able to return complex objects as well and the API will automatically serialize the results in a JSON document format that can be used on the client-side to provide a clear response.
Please see these two tutorials:
How do I get ASP.NET Web API to return JSON instead of XML using Chrome? - Stack Overflow
Format response data in ASP.NET Core Web API | Microsoft Docs
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
But they're void methods. There's nothing to return
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Change your void methods to return IActionResult , and return a result representing the status of the operation.
Controller action return types in ASP.NET Core web API | Microsoft Docs[^]
Eg:
[HttpDelete]
public IActionResult Delete(int id)
{
if (!RecordExists(id)) return NotFound();
DeleteTheRecord(id);
return Ok();
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm using .Net Framework. I can't use IActionResult
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
For .NET Framework, you just need to use IHttpActionResult instead.
[HttpDelete]
public IHttpActionResult Delete(int id)
{
if (!RecordExists(id)) return NotFound();
DeleteTheRecord(id);
return Ok();
} Action Results in Web API 2 - ASP.NET 4.x | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello,
I am working on a project that requires me to code multiple text blocks over an image (a diagram). But the way I coded it will not allow the image to render in any other page view other than full screen. When changing the screen size, the text gets all jumbled up. Can you please help me understand the correct way to code text over an image and have the text convert with the image as the screen size changes?
|
|
|
|
|
I wanted to ask how should we code the domain code ourselves? That is, to register a domain for our website and not to get it from somewhere else? What to learn for it Or what book he read
|
|
|
|