Safari 中使用 Primefaces 的 Jquery ajax $.post() 方法问题

发布于 2025-01-04 03:39:50 字数 2317 浏览 0 评论 0原文

jquery ajax $.post() 方法在 Safari 3.2.3 (525.29) 或其他版本中工作吗?

我试图在用户输入内容时动态获取一些信息,但它似乎不起作用。

另外,在其他 Safari 版本(我刚刚在版本 5 上进行了测试)中,此功能运行良好,IE 和其他版本也运行良好。

谁能向我确认这一点,或者给我更多有关 Safari 的 $.post() 的信息,或者有关 primefaces 的 jquery 库的信息或问题?

我非常感谢您的意见。

已编辑

我正在使用带有 primefaces 的 jquery 库,我有以下内容,只是一个示例或代码片段:

// 1. I imported a base64.js that has this structure: (This .js is obfuscated for security)

// methods situated at base64.js
var key = "b3NjYXJqY";


    function base64key(){
        this.key = function(){
            return key;
        };
    }

function decrypt(val){
    //method that just plays with the string passed in the parameter (val)
    return decryptedString;
}

/****************************************************************************/
/* 2. Data returned in the callback is an encrypted json from java servlet. */
/****************************************************************************/

// value from my input
var identifier = $('#txtid').val();

$.post('MyServlet', {identifier : identifier} , function(data) {

    // MyServlet returns 0 if no data, else returns an encrypted json as base64 generated with a key.
    if (data != 0) {

        // base64key() is a method from base64.js that just return a key (like b3NjYXJqY)
        var b = new base64key();

        // variable that contains encrypted json as string
        var temp = data.replace(b.key().substring(5), '');

        // decrypt the json (temp variable)
        var json = decrypt(temp).replace(b.key(), '');

        // parse the json string
        var info = JSON.parse(json);

        // fill the inputs with data
        $('#txtname').val(info.name);
        $('#txtemail').val(info.email);
        $('#txtphone').val(info.phone); 
});

/**********************************************************************************/
/* 3. Just to have an idea of the "data" structure, this is the decrypted json.   */
/**********************************************************************************/
{"name": "Oscar Jara", "email": "[email protected]", "phone": "+45 88779900"}

Did jquery ajax $.post() method work in Safari 3.2.3 (525.29) or other?

I am trying to get some information dynamicly when user types on an input but It seems to doesn't work.

Also, in other Safari versions (I just tested on version 5) this is working good and also IE and others.

Could anyone confirm to me this or give me more information regarding $.post() with Safari or maybe information or issues about jquery library from primefaces?

I will really appreciate your opinions.

EDITED

I am using jquery library with primefaces and I have the following, just an example or code snippets:

// 1. I imported a base64.js that has this structure: (This .js is obfuscated for security)

// methods situated at base64.js
var key = "b3NjYXJqY";


    function base64key(){
        this.key = function(){
            return key;
        };
    }

function decrypt(val){
    //method that just plays with the string passed in the parameter (val)
    return decryptedString;
}

/****************************************************************************/
/* 2. Data returned in the callback is an encrypted json from java servlet. */
/****************************************************************************/

// value from my input
var identifier = $('#txtid').val();

$.post('MyServlet', {identifier : identifier} , function(data) {

    // MyServlet returns 0 if no data, else returns an encrypted json as base64 generated with a key.
    if (data != 0) {

        // base64key() is a method from base64.js that just return a key (like b3NjYXJqY)
        var b = new base64key();

        // variable that contains encrypted json as string
        var temp = data.replace(b.key().substring(5), '');

        // decrypt the json (temp variable)
        var json = decrypt(temp).replace(b.key(), '');

        // parse the json string
        var info = JSON.parse(json);

        // fill the inputs with data
        $('#txtname').val(info.name);
        $('#txtemail').val(info.email);
        $('#txtphone').val(info.phone); 
});

/**********************************************************************************/
/* 3. Just to have an idea of the "data" structure, this is the decrypted json.   */
/**********************************************************************************/
{"name": "Oscar Jara", "email": "[email protected]", "phone": "+45 88779900"}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜妞爱困 2025-01-11 03:39:50

我会回答我自己的问题...

问题不是 jQuery POST,问题是 JSON 与某些浏览器根本不兼容,看看这个:

http://caniuse.com/json

我在 Safari 中遇到错误,并出现类似的错误“JSON 变量无法被识别”开发者控制台。

要解决这个问题,您需要使用一个名为 json2.js 的库,它的效果非常好。
您可以在这里找到文档和下载:

https://github.com/douglascrockford/JSON-js

I will answer my own question...

The problem was not the jQuery POST, the problem was JSON that is not compatible with some browsers at all, take a look at this:

http://caniuse.com/json

and I was facing an error with Safari and an error similar like this appeared "JSON variable wansn't able to be recognized" in the developer's console.

To solve this you need to use a library called json2.js that works really good.
Here you can find documentation and downloads:

https://github.com/douglascrockford/JSON-js

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文