gpt4 book ai didi

javascript - 我的 Ajax 调用。总是返回错误

转载 作者:行者123 更新时间:2023-11-27 23:09:19 24 4
gpt4 key购买 nike

大家好,我在 magento 工作,我搜索了很多,但没有得到任何解决方案,这是我的 ajax

var $wk_jq = jQuery.noConflict();
$wk_jq.ajax({
url : "<?php echo $this->getUrl('mpmassuploadaddons/index/runProfiler'); ?>",
type : 'GET',
data : {id : profilerId,row : countOfStartedProfiles},
dataType : 'json',
success : function(content) {
console.log('content success');

},
error: function(xhr, textStatus, errorThrown) {
console.log(xhr);
console.log(textStatus);
console.log(errorThrown);
}
});

我总是遇到解析器错误

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
responseText "NULL\nNULL\n{"savedRows":1...":"successfully saved"}"
status 200
statusText "OK"

即使我的 php 代码也工作正常,并返回 json 编码字符串 {"savedRows":1,"success":"成功保存"} 以及成功消息,这里是我的 php 代码

public function runProfilerAction() {
ob_start();
$profileId = $this->getRequest()->getParam('id');
$rowCount = $this->getRequest()->getParam('row');
$profile = Mage::getModel('mpmassuploadaddons/profilesession')->load($profileId);
if($profile->getproductType() == "simple") {
$result = Mage::getModel('mpmassuploadaddons/mpmassupload')->importSimpleProducts($profileId,$rowCount);
} elseif($profile->getproductType() == "downloadable") {
$result = Mage::getModel('mpmassuploadaddons/mpmassupload')->importDownloadableProducts($profileId,$rowCount);
} elseif($profile->getproductType() == "virtual") {
$result = Mage::getModel('mpmassuploadaddons/mpmassupload')->importVirtualProducts($profileId,$rowCount);
} elseif($profile->getproductType() == "configurable") {
$result = Mage::getModel('mpmassuploadaddons/mpmassupload')->importConfigurableProducts($profileId,$rowCount);
}

echo json_encode($result);
}

这个json {"savedRows":1,"success":"successively save"} 的格式也是正确的,我已经在这里解码了 http://json.parser.online.fr/

没关系,请帮忙谢谢

最佳答案

添加这个

ob_clean();

json_encode之前

希望它能起作用......

关于javascript - 我的 Ajax 调用。总是返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36307075/

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