相关疑难解决方法(0)

NodeJS不会将数据返回给jQuery.getJSON

当我浏览到URL时,我已经设置了NodeJS并返回数据:http://184.106.206.235

然而,当我尝试使用调用该URL $.getJSON,回调显示nulldata变量,"success"textStatus变量.

我想这可能是一个跨领域的事情,但我很惊讶textStatus说,"success"如果是这样的话.

万一它有用,这里是服务器端的JS:

http.createServer(function(req, res){
  var output = {message: "Hello World!"};
  var body = JSON.stringify(output);

  res.writeHead(200, {'Content-Type': 'application/json', 'Content-Length': body.length});
  res.end(body);
}).listen(80, "184.106.206.235");
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

jquery getjson node.js

12
推荐指数
1
解决办法
6466
查看次数

JavaScript如何保存到本地文件?

已经有一个在线编写文件JSON的解决方案,但我想在本地保存json文件.我试过使用这个例子http://jsfiddle.net/RZBbY/10/ 它创建了一个下载文件的链接,使用此调用 a.attr('href', 'data:application/x-json;base64,' + btoa(t.val())).show(); 有没有办法在本地保存文件而不是提供可下载的链接?还有其他类型的转换data:application/x-json;base64吗?

这是我的代码:

<!DOCTYPE html>
<head> 
    <meta charset="utf-8">
    <title>jQuery UI Sortable - Default functionality</title>

    <link rel="stylesheet" href="http://jqueryui.com/themes/base/jquery.ui.all.css">
    <script src="http://jqueryui.com//jquery-1.7.2.js"></script>
    <script src="http://jqueryui.com/ui/jquery.ui.core.js"></script>
    <script src="http://jqueryui.com/ui/jquery.ui.widget.js"></script>
    <script src="http://jqueryui.com/ui/jquery.ui.mouse.js"></script>
    <script src="http://jqueryui.com/ui/jquery.ui.sortable.js"></script>
        <script src="http://jqueryui.com/ui/jquery.ui.accordion.js"></script>
    <link rel="stylesheet" href="http://jqueryui.com/demos/demos.css">        
    <meta charset="utf-8">
    <style>a { font: 12px Arial; color: #ac9095; }</style>
<script type='text/javascript'>
$(document).ready(function() {
var f = $('form'), a = $('a'),
    i = $('input'), t = $('textarea');

$('#salva').click(function() {
    var o = {}, v = t.val();

    a.hide();//nasconde il contenuto
    i.each(function() …
Run Code Online (Sandbox Code Playgroud)

javascript jquery json jsonp

12
推荐指数
4
解决办法
9万
查看次数

iPhone上的JSON POST请求(使用HTTPS)

我托管了一个WCF服务,我试图在iPhone应用程序中使用它作为JSON POST请求.我打算稍后使用JSON序列化程序,但这是我对请求的要求:

    NSString *jsonRequest = @"{\"username\":\"user\",\"password\":\"letmein\"}";
    NSLog(@"Request: %@", jsonRequest);

    NSURL *url = [NSURL URLWithString:@"https://mydomain.com/Method/"];

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
    NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest length]];

    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
    [request setHTTPBody: requestData];

    [NSURLConnection connectionWithRequest:[request autorelease] delegate:self];
Run Code Online (Sandbox Code Playgroud)

在收到的数据中,我只是将其打印到控制台:

- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    NSMutableData *d = [[NSMutableData data] retain];
    [d appendData:data];

    NSString *a = [[NSString alloc] initWithData:d encoding:NSASCIIStringEncoding];

    NSLog(@"Data: %@", a);
}
Run Code Online (Sandbox Code Playgroud)

在这个回复中,我得到了这样的信息:

Data: <?xml version="1.0" …
Run Code Online (Sandbox Code Playgroud)

iphone ssl https json objective-c

11
推荐指数
1
解决办法
4万
查看次数

如何在CakePHP中为JSON返回正确的内容类型?

我正在尝试为使用AJAX GET请求访问的JSON响应设置content-type标头.我已经关注了博客和面包店的教程,但我总是从CakePHP收到'text/html'.如何正确设置内容类型标题?

这是我目前的代码:

public function admin_controller_actions_ajax()
{
    Configure::write('debug', 0);
    if ($this->RequestHandler->isGet()) {
        $this->autoRender = FALSE;

        $aco_id = $this->params['url']['aco_id'];
        $aro_id = $this->params['url']['aro_id'];

        assert('$aco_id != NULL && $aro_id != NULL &&
                is_numeric($aco_id) && is_numeric($aro_id)');

        $actions = $this->Resource->getActionsForController($aco_id, $aro_id);

        assert('is_array($actions) && is_array($actions[0])');

        /* I made RequestHandler part of the $components property */
        $this->RequestHandler->setContent('json');
        $this->RequestHandler->respondAs('json'); /* I've tried 'json', 'JSON', 'application/json' but none of them work */

        $this->set('json_content', json_encode(array('response' => $actions[0])));
        $this->layout = NULL;
        $this->render('/json/default');
    }
}


/* json/default.ctp */
<?php echo $json_content; ?> …
Run Code Online (Sandbox Code Playgroud)

php ajax json content-type cakephp

10
推荐指数
3
解决办法
1万
查看次数

Delphi HTTP Post JSON

我相信我在这里做错了.我已经跟踪了我在stackoverflow上找到的每个例子,但仍然没有在我的环境中使用它.我想更新我的控件和环境,但我现在已经锁定了我拥有的东西.

我在用:

  • 德尔福7
  • Indy 10.0.52
  • ulkJSON.pas v1.07

我需要将此JSON发送到URL:

"auth": {
    "applicationId": "appID",
    "applicationPassword": "pwd",
    "accountId": "acct",
    "userId": "dev"
}
Run Code Online (Sandbox Code Playgroud)

这没有什么可怕的,但当我尝试发布我的请求时,我倾向于收到一条消息,请求是优雅地关闭.IDSocketHandle.pas中的CheckIsReadable具有Handleallocated = false.我不确定在配置我的IdHTTP时我做错了什么,但它不起作用.

我已经尝试了所有这些问题和其他几个问题的例子,但这些方法似乎都不适合我:

任何提示将非常感谢.

当前变体如下所示:

procedure Tformmaintestbed.btnJSONSendClick(Sender: TObject);
var
  code: Integer;
  sResponse: string;
  JsonToSend: TStringStream;
begin
  JsonToSend := TStringStream.Create(
    '{"auth": {"applicationId": "' + edApplication.text +
    '","applicationPassword": "' + edpassword.text +
    '","accountId": "' + edaccount.text +
    '","userId": "' + edUser.text +
    '"}}');
  try
    HTTP1.Request.ContentType := 'application/json';
    HTTP1.Request.ContentEncoding := 'utf-8';

    memoRequest.lines.clear;
    memoRequest.lines.add(JsonToSend); …
Run Code Online (Sandbox Code Playgroud)

delphi json indy

10
推荐指数
1
解决办法
4万
查看次数

让json_encode不能逃脱html实体

我将json_encoded数据从我的PHP服务器发送到iPhone应用程序.包含html实体的字符串会'&'被转义json_encode并作为&amp;.

我期待做两件事之一:

  • 使json_encode无法逃避的HTML实体.Doc说'正常'模式不应该逃脱它,但它对我不起作用.有任何想法吗?

  • 使iPhone应用程序廉价地解除html实体.现在我能想到的唯一方法XML/HTML parser就是花一些非常昂贵的东西.任何更便宜的建议?

谢谢!

php iphone cocoa json objective-c

9
推荐指数
1
解决办法
2万
查看次数

如何在ASP.NET MVC路由中使用HttpMethodConstraint的自定义约束?

我有一个控制器只接受此URL上的POST:

POST http://server/stores/123/products
Run Code Online (Sandbox Code Playgroud)

POST应该是content-type application/json,所以这就是我在路由表中的内容:

routes.MapRoute(null,
                "stores/{storeId}/products",
                new { controller = "Store", action = "Save" },
                new {
                      httpMethod = new HttpMethodConstraint("POST"),
                      json = new JsonConstraint()
                    }
               );
Run Code Online (Sandbox Code Playgroud)

在哪里JsonConstraint:

public class JsonConstraint : IRouteConstraint
{
    public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
    {
        return httpContext.Request.ContentType == "application/json";
    }
}
Run Code Online (Sandbox Code Playgroud)

当我使用这条路线时,我得到了一个405 Forbidden:

The HTTP verb POST used to access path '/stores/123/products' is not allowed

但是,如果我删除json = new JsonConstraint()约束,它工作正常.有人知道我做错了什么吗?

asp.net-mvc routing asp.net-mvc-routing

8
推荐指数
1
解决办法
1838
查看次数

浏览器对json ajax响应的Content-Type标头需要什么?

我正在返回一些需要通过javascript处理的json作为对XMLHTTPRequest的响应.

如果我将响应的内容类型设置为"text/plain",那么除Chrome之外的所有浏览器都会接受它并将其传递给我的JS而没有任何问题.但是,Chrome会将响应包装在中

<pre style="word-wrap: break-word; white-space: pre-wrap;"> 
Run Code Online (Sandbox Code Playgroud)

在将它传递给我的javascript之前.

如果我将响应的内容类型设置为"正确的""application/json"所有浏览器,但Firefox会接受它并将其传递给我的JS而没有任何问题.但是,Firefox会要求将响应保存或打开为文件.

什么是正确的跨浏览器内容类型?

ajax json content-type xmlhttprequest cross-browser

8
推荐指数
1
解决办法
7046
查看次数

jQuery和JSON vs IE - SCRIPT5007:无法获得该属性的价值

我很难让这个脚本工作.它基本上是一个简单的ajax调用,用于从php中检索返回JSON代码的数据.

function refreshWindows(){
if(AjaxPull && AjaxPull.readystate != 4){
    AjaxPull.abort();
}
AjaxPull = $.ajax({
    type: 'POST',
    url: $path,
    data: {
        ajax: true,
        mode: 'update',
        to: Math.round(currentDate.getTime() / 1000),
        from: Math.round(previousDate.getTime() / 1000)
    },
    dataType: "json",
    success: function (data) {
        alert(data); //that's for debug
        $replies = data.Updates;
        $.each($replies ,function(group,value) {
            if (value!=''){
                $("#group"+group+" .content").append(value);
                $("#group"+group+" .content").stop().animate({ scrollTop: $("#group"+group+" .content")[0].scrollHeight }, 800);
                if (!$("#group"+group+" .Window").is(':visible')) {
                    $("#group"+group+" .BottomBox").fadeTo('fast', 0.5).fadeTo('fast', 1.0);
                }
            }
        });
        previousDate = currentDate;
        currentDate = new Date();
        timeController.push( setTimeout(function(){refreshChatWindows();}, 500) …
Run Code Online (Sandbox Code Playgroud)

jquery internet-explorer json

8
推荐指数
1
解决办法
3828
查看次数

使用 AspNet [FromQuery] 模型绑定中的 EnumMember 值反序列化枚举

我在 .NET 6 项目中有一个端点Microsoft.NET.Sdk.Web,它使用标准 [FromQuery] 将查询字符串反序列化为 .NET 对象

[Route("[controller]")]
public class SamplesController
    : ControllerBase
{
    [HttpGet]
    public IActionResult Get([FromQuery]QueryModel queryModel)
    {
        if (!queryModel.Status.HasValue)
        {
            return BadRequest("Problem in deserialization");
        }
        
        return Ok(queryModel.Status.Value.GetEnumDisplayName());
    }
}
Run Code Online (Sandbox Code Playgroud)

该模型包含一个枚举

public class QueryModel
{
    /// <summary>
    /// The foo parameter
    /// </summary>
    /// <example>bar</example>
    public string? Foo { get; init; } = null;
    
    /// <summary>
    /// The status
    /// </summary>
    /// <example>on-hold</example>
    public Status? Status { get; set; } = null;
}
Run Code Online (Sandbox Code Playgroud)

枚举具有EnumMember …

enums jsonserializer custom-model-binder asp.net-core system.text.json

7
推荐指数
1
解决办法
2213
查看次数