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

我正在使用$.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'}" . ')';

在这是我在萤火虫中得到的回应.

截图-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'}" . ')';

相关文章

IE6是一个非常老旧的网页浏览器,虽然现在很少人再使用它,但...
PHP中的count()函数是用来计算数组或容器中元素的个数。这个...
使用 AJAX(Asynchronous JavaScript and XML)技术可以在不...
Ajax(Asynchronous JavaScript and XML)是一种用于改进网页...
本文将介绍如何通过AJAX下载Excel文件流。通过AJAX,我们可以...
Ajax是一种用于客户端和服务器之间的异步通信技术。通过Ajax...