gpt4 book ai didi

javascript - 在 JsonP 中得到不正确的响应

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

我正在使用 $.ajax 方法将数据从 index.php 文件发送到另一个 exec.php 文件并在该文件上执行数据现在文件当我使用 jsonp 回调发回输出数据时,我在 index.php 上得到不正确的数据。我还将相同的输出数据写入 exec.php 上的 txt 文件,并且我在 txt 文件中获得了正确的数据。

这是我从 index.php 调用的 ajax

$.ajax({
type: 'GET',
url: 'exec.php',
dataType: 'JSONP',
data: {code : code},
success: function(data)
{
alert(data);
$(loader).addClass('hidden');
var stdout = $(form).children('.stdout');
if (data.search("Parse error")>0)
{
var str = data.replace('<b>Parse error</b>: ','');
$(stdout).html(str);
$(stdout).removeClass('hidden');
}
else
{
$(stdout).html(data);
$(stdout).removeClass('hidden');
}
},
error: function (status,req,err) {
var errorMessage = err || req.statusText;
alert(errorMessage);
}, // When Service call fails

responseType: "jsonp"
});

这是我来自 exec.php 的 json 回调代码

$result = str_replace('"','\"', $script_output);
$script_output = str_replace('"','\"', $script_output);
$file = fopen("test.txt","w");
echo fwrite($file,$script_output);
fclose($file);
//print "processJSON({'result':'$result'})";
header('Content-Type: application/jsonp');
echo $_GET['callback'] . '(' . "{'result' : '$result'}" . ')';

现在这是我在 Firebug 中得到的响应。

屏幕截图 - http://screencast.com/t/nqdAR7JedMk我通过 ajax 方法的错误通过警报收到此错误截图 - http://screencast.com/t/5RRlYiha2C0

请告诉我我哪里错了

最佳答案

我已经找到答案了。额外的号码通过 json 回调返回。所以我已经注释掉了,我的一些代码和我的完美输出就在这里,

$result = str_replace('"','\"', $script_output);
$script_output = str_replace('"','\"', $script_output);
//$file = fopen("test.txt","w");
//echo fwrite($file,$script_output);
//fclose($file);
//print "processJSON({'result':'$result'})";
header('Content-Type: application/jsonp');
echo $_GET['callback'] . '(' . "{'result' : '$result'}" . ')';

关于javascript - 在 JsonP 中得到不正确的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20542905/

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