小编ale*_*lex的帖子

如何在 XAMPP 上启用跨域资源共享?

我的本地主机上有一个 html 文件,其中包含一个表单和处理发布数据的 jquery/ajax。一个简单的php脚本在mysql数据库表中查找数据

这是主要部分:

// $.post('lookup_update.php', $(this).serialize()) //<- local part which works
   $.post('http://www.example.com/projectX/lookup_update.php', $(this).serialize()).done(function (data)
                            { etc.
Run Code Online (Sandbox Code Playgroud)

但是当我指向在线 lookup_update.php 时,我在 chrome 中收到以下错误消息

XMLHttpRequest 无法加载http://www.example.com/projectX/lookup_update.php。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问Origin ' http://localhost '。响应具有 HTTP 状态代码 404。

据我了解,我需要使用

 header("Access-Control-Allow-Origin: *");
Run Code Online (Sandbox Code Playgroud)

对于 php。但是当我将它添加到 example.com/lookup_update.php 时,当 localhost 文件尝试调用它时,该文件会给出 404。

我还尝试将以下内容添加到我的 Xampp apache 配置文件中

Header set Access-Control-Allow-Origin "*"
Run Code Online (Sandbox Code Playgroud)

如何从我的本地 XAMPP 设置中正确启用跨源资源?

[编辑]这是我在本地主机上的简单表格

<!--Begin form-->
    <div id="form" class="result">
        <form method="post" id="reg-form"  class="form-horizontal">
            <div class="controls">
                <input type="text" name="code" id="code" placeholder="Code"  class="form-control input-lg" />      
            </div>
        </form>
    </div>
    <!--End …
Run Code Online (Sandbox Code Playgroud)

php apache config cross-domain

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

如何在选择菜单中选择第一个空值选项?

以下始终预先选择最后一个选项,即使我设置了selected属性,但我喜欢预先选择的第一个选项.

<select name="filter">
    <option value="" selected>Make a choice</option>
    <option value="1">1</option>
    <option value="3">3</option>
    <option value="7">7</option>
    <option value="">all</option>
</select>
Run Code Online (Sandbox Code Playgroud)

可以这样做吗?

html xhtml option

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

Googlemap api v3比api v2慢?

我正在将旧的googlemap v2代码转换为v3,它看起来v3是否比v2慢得多?

我的大多数代码更改只是用google.maps替换G. (GMarker google.maps.Marker)

任何提示或技巧如何加快速度?

google-maps google-maps-api-3 google-maps-api-2

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

试图导出到csv但我如何从委托实现?

[new to swift]我测试这个函数来导出一些简单的文件

    @IBAction func exportFile(delegate: UIDocumentInteractionControllerDelegate) {
        print("export csv")
       let fileName = tmpDir.stringByAppendingPathComponent("myFile.csv")
        let url: NSURL! = NSURL(fileURLWithPath: fileName)

        if url != nil {
            let docController = UIDocumentInteractionController(URL: url)
            docController.UTI = "public.comma-separated-values-text"
            docController.delegate = delegate
            docController.presentPreviewAnimated(true)

        }
}
 // Return the view controller from which the UIDocumentInteractionController will present itself.
    func documentInteractionControllerViewControllerForPreview(controller: UIDocumentInteractionController)-> UIViewController {
        return self
    }
Run Code Online (Sandbox Code Playgroud)

但是当我点击导出按钮时,我收到了消息

UIDocumentInteractionController delegate must implement documentInteractionControllerViewControllerForPreview: to allow preview
Run Code Online (Sandbox Code Playgroud)

我想

class ViewController:UIViewController,UIDocumentInteractionControllerDelegate {

会足够吗?

我试过Self.documentInteractionControllerViewForPreview(docController)

[编辑]原来我犯了以下错误docController.delegate = self //委托

delegates implements ios swift

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

如何将字典作为函数参数传递?

我试图将字典作为函数参数传递.我有以下功能

func makeAndAddVisitorRecord2(visitorDict: Dictionary) -> ABRecordRef <AnyObject, AnyObject> {
    let visitorRecord: ABRecordRef = ABPersonCreate().takeRetainedValue()
    ABRecordSetValue(visitorRecord, kABPersonFirstNameProperty, visitorDict[1], nil)
    ABRecordSetValue(visitorRecord, kABPersonLastNameProperty, visitorDict[2], nil)
    //ABRecordSetValue(visitorRecord, kABPersonEmailProperty, visitorDict[5], nil)

    let phoneNumbers: ABMutableMultiValue =
    ABMultiValueCreateMutable(ABPropertyType(kABMultiStringPropertyType)).takeRetainedValue()
    ABMultiValueAddValueAndLabel(phoneNumbers, visitorDict["visitorPhone"], kABPersonPhoneMainLabel, nil)
    ABRecordSetValue(visitorRecord, kABPersonPhoneProperty, phoneNumbers, nil)

    ABAddressBookAddRecord(addressBookRef, visitorRecord, nil)
    saveAddressBookChanges()

    return visitorRecord
}
Run Code Online (Sandbox Code Playgroud)

我喜欢触发哪个

func addVisitorToContacts(sender: AnyObject) {
    //let visitor = ListVisitors[visitorButton.tag]
    var visitorDict:[Int:String] = [1:"\(visitorName)", 2:"\(visitorCompany)", 3:"\(visitorCity)",
        4:"\(visitorPhone)", 5:"\(visitorEmail)"]

    let visitorRecord: ABRecordRef = makeAndAddVisitorRecord2(visitorDict)
    let contactAddedAlert = UIAlertController(title: "\(visitorName) was successfully added.",
        message: nil, preferredStyle: .Alert) …
Run Code Online (Sandbox Code Playgroud)

dictionary swift

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

简单的命名锚在FF中不起作用,但它在IE中起作用

我有a href链接:

/agenda/#Testevent
Run Code Online (Sandbox Code Playgroud)

在IE中它转到相应的<h4>元素,但在Firefox中它不起作用.

我使用过这个命名锚:

<h4 name="#Testevent" id="#Testevent">
Run Code Online (Sandbox Code Playgroud)

有什么建议?

html firefox internet-explorer

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

javascript全局变量可以容纳多少数据?

要使用ajax div启用返回功能,我创建了这些简单的函数,我想知道.js全局变量可以容纳多少数据?

    var dataAfterSearch; //global variable which holds our search results

function goBackAfterSearch() {
    /**
    *   function which displays the previous state
    *
    **/
    $.ajaxSetup ({
        cache: false
    });
    //alert("Previous Search" +dataAfterSearch);
    $('#result').html(dataAfterSearch);
     paginateIt();
}
function setDataAfterSearch(data)
{   
    /**
    * function to set the global dataAfterSearch
    *
    **/
    dataAfterSearch = data;
}
Run Code Online (Sandbox Code Playgroud)

亲切的问候

ajax

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

在div中按名称选择输入按钮?

HTML:

<div id="div1">
  <div class="row" >
     <div class="span2" >
    <input type=button  value="" name="btn1"/>
    </div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)

jQuery的:

$(document).ready(function() {
        $('#div1[name="btn1"]').val('test hello');
            });
Run Code Online (Sandbox Code Playgroud)

为什么这不起作用?

哪里

  $(document).ready(function() {
            $('[name="btn1"]').val('test hello');
                });
Run Code Online (Sandbox Code Playgroud)

似乎工作,但我有一些其他div,我需要填充值.

我可以重用输入元素的名称,还是必须是唯一的?

jquery jquery-selectors

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

jquery删除div和以前的标签?

这些是我需要删除的一些输入字段,但我无法删除标签标记

 <label class="prfx-row-title">Unique Selling Proposition </label>
 <div class="prfx-row-content">
     <input type="text" name="dynamic_usp[0][text]" placeholder="unique selling proposition " value="testing hello world" />
     <span class="remove button">Remove USP</span>
 </div>

$(".remove").live('click', function() {
            $(this).parent().remove();
            $(this).parent().prev('label.prfx-row-title').remove();
        });
Run Code Online (Sandbox Code Playgroud)

现在只删除div但不删除标签?

任何人?

html javascript jquery dom dom-manipulation

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

如何快速更新字典键?

我正在尝试制作一个带有型号名称和价格的两列表。每个模型都可以编辑和保存(另见)。为此,我想我需要一本字典:

var models = ["iPhone 6 plusss Gold 128 GB" : 1000,"iPhone 6 Plus Gold 64 GB" : 500, "iPhone 6 Gold 128 GB" : 250, "iPhone 6 Gold 16 GB" : 100]
Run Code Online (Sandbox Code Playgroud)

但是我想更新键 0,因为例如我拼错了“plusss”。我怎样才能做到这一点?

我找到了如何更新键值对:

models.updateValue(200, forKey: "iPhone 6 Gold 16 GB")
Run Code Online (Sandbox Code Playgroud)

但是我如何更新密钥?

[编辑] 显然我正在以错误的方式“思考”它。我正在阅读词典,我认为最好的方法是上课(如 vdian 评论)

dictionary swift

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