我将身体中的 JSON 发送到我的 API 控制器,但不断收到以下错误。
{"":["解析值时遇到意外字符:{.路径'',第1行,位置1。"]}
我的 HTTP 请求
HttpClient client = new HttpClient();
HttpRequest httpRequest;
HttpResponseMessage httpResponse = null;
httpRequest = new HttpRequest("", HostnameTb.Text, null);
var values = new Dictionary<string, string>
{
{ "APIKey", APIKeyTb.Text }
};
string json = JsonConvert.SerializeObject(values);
StringContent content = new StringContent(json.ToString(), Encoding.UTF8, "application/json");
httpResponse = client.PostAsync(HostnameTb.Text, content).Result;
var responseString = await httpResponse.Content.ReadAsStringAsync();
Run Code Online (Sandbox Code Playgroud)
我的控制器看起来像这样。
[HttpPost]
public void Post([FromBody] string value)
{
//Never gets here.
}
Run Code Online (Sandbox Code Playgroud)
体内的 Json。
{"APIKey":"1283f0f8..."}
我更喜欢使用 .Net Core[From Body] …
问题
我将尝试尽可能多地包含信息而不会使事情变得复杂,但我有一个问题,当我提交表单时,页面刷新,从而关闭表单上的选项卡.然后,用户需要再次单击选项卡以查看反馈.
背景信息
我有一个使用JavaScript打开和关闭"标签"(div)的网页,在其中一个标签上我有一个表格,用户将数据输入到php脚本,然后将数据发送到电子邮件地址,然后重定向回原始页面.但是,当脚本重定向回页面时,选项卡将关闭,从而使用户重新单击选项卡以再次打开它以查看脚本的自动反馈.
我检查了什么
我已经检查过,并不是重定向导致刷新,因为它仍然发生在POST表单自身时.
有没有人有任何想法?
这是表单的HTML,位于查询"选项卡"中.
<div class='content one'>
<div id="contact-form" class="clearfix">
<P>Quick And Easy!</P>
<br/>
<P>Fill out our super swanky contact form below to get in touch with us! Please provide as much information as possible for us to help you with your enquiry.</P>
<br/>
<?php
//init variables
$cf = array();
$sr = false;
if(isset($_SESSION['cf_returndata'])){
$cf = $_SESSION['cf_returndata'];
$sr = true;
}
?>
<ul id="errors" class="<?php echo ($sr && !$cf['form_ok']) ? 'visible' : ''; ?>">
<li …Run Code Online (Sandbox Code Playgroud) 这可能吗?
一旦我的jQuery.post成功,而不是只有一个成功回调我有两个.
例如
一旦我的表单成功发布了数据,就会给出一个名为"#msg"的空div给定样式和内容,并给出一个名为"color-block"的空div.
代码到目前为止
$('#form1').submit(function(e)
{
e.preventDefault();
$.ajax({
type: 'POST',
url: 'indextest1.php',
data: $("#form1").serialize(),
success: function(response) {
$('#msg').html("<div style='border: 1px solid black; padding:15px 50px 15px 20px; width:437px; border-radius: 8px; background:#D3EDD3 url(img/accepted_48.png) no-repeat 450px center;'>Now sit back and relax.....</div>");
}
});
});
Run Code Online (Sandbox Code Playgroud)
任何帮助或指针将不胜感激.
我尝试过但没有奏效的事情!
添加另一个回调
$('#form1').submit(function(e)
{
e.preventDefault();
$.ajax({
type: 'POST',
url: 'indextest1.php',
data: $("#form1").serialize(),
success: function(response) {
$('#msg').html("<div style='border: 1px solid black; padding:15px 50px 15px 20px; width:437px; border-radius: 8px; background:#D3EDD3 url(img/accepted_48.png) no-repeat 450px center;'>Now sit back and …Run Code Online (Sandbox Code Playgroud) 问题
我有三个媒体查询,一个用于移动,平板电脑和桌面屏幕尺寸.一切正常,直到我必须做了一些阻止平板电脑媒体查询工作/激活的东西?
我知道它不起作用,因为导航菜单设置为与其他两个查询显示不同.
每个都应显示如下图.
电话

片剂

桌面

究竟发生了什么?
在调整浏览器窗口大小后,将跳过平板电脑媒体查询,直接从桌面切换到移动查询.
实例
我的HTML
<!doctype html>
<!--[if lt IE 7]> <html class="ie6 oldie"> <![endif]-->
<!--[if IE 7]> <html class="ie7 oldie"> <![endif]-->
<!--[if IE 8]> <html class="ie8 oldie"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="">
<!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Untitled Document</title>
<link href="boilerplate.css" rel="stylesheet" type="text/css">
<link href="fluid.css" rel="stylesheet" type="text/css">
<!--
To learn more about the conditional comments around the html tags at the top of the file:
paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/
Do …Run Code Online (Sandbox Code Playgroud)