jquery中ajax請求后台數據成功后既不執行success也不執行error解決方法


jquery中ajax請求后台數據成功后既不執行success也不執行error,此外系統報錯:Uncaught SyntaxError: Unexpected identifier at Object.success,但后台能夠返回數據,原代碼如下:

        var source=[];
	$.ajax({     
		type: "post",     
		url: "connectdb/select.jsp",        
		data: {database: "scmdb", selectsql: sql}, 
		async: false, method: 'post',    
		dataType: "json", 
		success: function(data) {     
			eval("source="+data+";");
			//source=eval(data); 
			alert("正確");
		},
		error: function(err) {   
		    alert("錯誤");     
		}
	});
	return source;  

主要原因在於后台返回的數據並非json格式,而在代碼中指定了 dataType: "json", 解決方法是將 json改為text,修改后的代碼如下:

        var source=[];
	$.ajax({     
		type: "post",     
		url: "connectdb/select.jsp",        
		data: {database: "scmdb", selectsql: sql}, 
		async: false, method: 'post',    
		dataType: "text", 
		success: function(data) {     
			eval("source="+data+";");
			//source=eval(data); 
			alert("正確");
		},
		error: function(err) {   
		    alert("錯誤");     
		}
	});
	return source;

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM