gpt4 book ai didi

javascript - 如何编码传递给 div.load() 的 URL?

转载 作者:可可西里 更新时间:2023-11-01 13:39:13 25 4
gpt4 key购买 nike

我正在使用 URL 重写和使用

 $('#somediv').load(query, function (response, status, xhr) {
if (status == "error") {
var msg = "Sorry there was an error: ";
$("#somediv").html(msg + xhr.status + " " + xhr.statusText);
}
});

但是当我的 query 包含 '?'、'&' 和 '=' 之类的字符时,div.laod() 将无法工作。当我如下所示传递参数时,div 渲染不会发生。

query ="http://vmsbawcm001.ed.cps.something.com/content/pms/Snapshot.html?date=2011-09-30&email=something@gmail.com&view=external"

但这行得通!

 query ="http://vmsbawcm001.ed.cps.something.com/content/pms/Snapshot.html"

那么我该如何以某种编码方式传递参数呢?欢迎或任何其他解决方案,因为我很无能..

经过更多研究,我怀疑是不是 @ 符号导致了问题。是这样吗?如果是,可能的解决方案是什么?

谢谢,阿达什

最佳答案

.load() 中的第二个参数用于传递查询数据。这是引用:http://api.jquery.com/load/ .

演示:http://jsfiddle.net/ThinkingStiff/EKHbQ/

HTML:

<div id="somediv"></div>

脚本:

var uri = 'http://vmsbawcm001.ed.cps.something.com/content/pms/Snapshot.html',
data = {date:"2011-09-30",email:"something@gmail.com",view:"external"};

$( '#somediv' ).load( uri, data, function ( response, status, xhr ) {

if ( status == 'error' ) {

var msg = 'Sorry there was an error: ';
$( '#somediv' ).html( msg + xhr.status + ' ' + xhr.statusText );

};

});

关于javascript - 如何编码传递给 div.load() 的 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7950132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com