【问题标题】:$.ajax POST opens an new window on IE8$.ajax POST 在 IE8 上打开一个新窗口
【发布时间】:2013-03-30 07:18:58
【问题描述】:

通过 ajax POST 提交客户信息时,我从 IE8(仅 IE8)收到了这个奇怪的响应。

动作正确执行,客户在CRM上创建,所有后续动作都被执行,但窗口也重新打开,即弹出顶部URL的新窗口...

我无法确定为什么会发生这种情况。我剥离了代码以仅包含 post 调用,但没有成功。

工作代码如下,出于安全原因,我只是拿了公司 ID。

有什么想法吗?

  • Javascript

    $(document).ready(function () {
        $('button').click(function () {
            postNsData();
        });
    });
    
    function postNsData() {
        var nsurl = 'https://forms.netsuite.com/app/site/crm/externalleadpage.nl';
        var datamin = {
            compid: xxxxxx, //Company ID -- it's a number.
            formid: 503,
            h: '1e705f3aa4570f197aef',
            leadsource: 8020,
            subsidiary: 2,
            email: 'email@gmail.com',
            firstname: 'John',
            lastname: 'Doe',
            phone: '1800902011',
        };
    
        $.ajax({
            type: 'POST',
            url: 'repost.php',
            data: 'url=' + nsurl + '&' + data,
            success: function (text, textStatus, jqXHR) {
                if (textStatus == 'success') {}
            }
        });
    }
    
  • PHP 代码 -- repost.php

    <? php
    //set POST variables
    $url = $_POST['url'];
    unset($_POST['url']);
    $fields_string = "";
    //url-ify the data for the POST
    foreach($_POST as $key = > $value) {
        $fields_string. = $key.'='.$value.'&';
    }
    
    $fields_string = rtrim($fields_string, '&');
    //open connection    
    $ch = curl_init();
    //set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, count($_POST));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
    //execute post
    
    $result = curl_exec($ch);
    
    //close connection
    
    curl_close($ch);
    
    ?>
    

【问题讨论】:

  • 不知道他们为什么做 IE..:P

标签: php javascript ajax post internet-explorer-8


【解决方案1】:

我认为你应该更新你的 javascript 使其看起来像这样

$(document).ready(function () {
    $('button').click(function (event) {
        event.preventDefault();
        postNsData();
    });
});

可能发生的情况是 IE 正确地假定您要执行链接并执行 javascript。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-24
    • 1970-01-01
    • 2023-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-15
    相关资源
    最近更新 更多