小编Tha*_*s P的帖子

如何使用新的Apple Swift语言发布JSON

我(试图)学习Swift的Apple语言.我在Playground并使用Xcode 6 Beta.我正在尝试向本地NodeJS服务器执行简单的JSON Post.我已经开始搜索它了,主要的教程解释了如何在一个项目中进行,而不是在PLAYGROUND,而不是写愚蠢的想法:"谷歌它"或"它很明显"或"看这个链接"或从不 - 测试 - 和 - 不官能码

这就是我正在尝试的:

var request = NSURLRequest(URL: NSURL(string: "http://localhost:3000"), cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData, timeoutInterval: 5)

var response : NSURLResponse?
var error : NSError?

NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error: &error)
Run Code Online (Sandbox Code Playgroud)

我试过了:

var dataString = "some data"

var request = NSMutableURLRequest(URL: NSURL(string: "http://posttestserver.com/post.php"))
request.HTTPMethod = "POST"

let data = (dataString as NSString).dataUsingEncoding(NSUTF8StringEncoding)

var requestBodyData: NSData = data
request.HTTPBody = requestBodyData

var connection = NSURLConnection(request: request, delegate: nil, startImmediately: false)

println("sending request...")
connection.start()
Run Code Online (Sandbox Code Playgroud)

谢谢!:)

post json ios swift

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

为什么代码在'return res.send();'之后仍然继续运行

我不明白为什么代码继续运行,即使在return和res.send()被调用之后.这是一个有助于理解的GIST.

更新:

好了,在社区的帮助下现在发现并了解问题是返回res.send();发生异步,并行console.log().

在这种特定情况下,解决方案是内部包装if/else.

感谢@Tom和@PaulPro!

javascript node.js express

6
推荐指数
1
解决办法
5496
查看次数

如何在PhantomJS测试中单击A指令

由Yeoman用角度发生器生成的应用程序.

指示:

angular.module('psApp').directive('scrollTop', function () {
  return {
    restrict: 'A',
    scope: true,
    template: '<a href="#" ng-click="click()" class="scroll-top"><span class="glyphicon glyphicon-arrow-up"></span> Back to top</a>',
    controller: ['$scope', '$element', '$document', function ($scope, $element, $document) {
      $scope.click = function () {
        $document.scrollTop(0, 500);
      };
    }]
  };
});
Run Code Online (Sandbox Code Playgroud)

测试:

describe('Directive: scrollTop', function () {

  // load the directive's module
  beforeEach(module('psApp'));

  var scope, element;

  beforeEach(inject(function ($rootScope, $compile) {
    scope = $rootScope.$new();
    element = $compile('<div scroll-top></div>')(scope);
    scope.$apply();
  }));

  it('should have "Back to top" as text', inject(function () { …
Run Code Online (Sandbox Code Playgroud)

javascript phantomjs angularjs yeoman yeoman-generator-angular

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

如何使用正则表达式将String.match()与$ {SOME_TEXT}区分开来

我需要这个字符串:

var x = 'Hi ${name}! How are you? ${name}, you are old! ${name} share with ${other} how do u ${feel}!'
Run Code Online (Sandbox Code Playgroud)

我需要知道使用正则表达式存在多少不同的$ {ANY_THING}.在上面的示例中,我预计3:$ {name},$ {other},$ {feel}

我正在尝试:

x.match(\${([a-zA-Z]))
Run Code Online (Sandbox Code Playgroud)

但输出是错误的:(

谢谢!

javascript regex string string-matching

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