web-view 指向的网页中,使用ajax报 400错误,何解?
发布于 8 年前 作者 yan80 3237 次浏览 来自 官方Issues

web-view 指向的网页中,使用ajax报 400错误,何解?

		function post( ajaxUrl, data, success, fail ){
			
			var param ={
				data:data,
				action:'my_action'
			}
			console.log( data);
			$.post( { 				
				url:"https://www.jss88.com.cn/bunengshuo",
				data:param,
				type:"post",
				contentType: "application/json",
				//dataType:"json",
				async : true,
				success: function( res){
					jRes = JSON.parse( res);
					console.log( jRes);
					success( jRes);
				}  
			});		
		}
		
		function ajaxObject() {
			var xmlHttp;
			try {
				// Firefox, Opera 8.0+, Safari
				xmlHttp = new XMLHttpRequest();
				} 
			catch (e) {
				// Internet Explorer
				try {
						xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
					} catch (e) {
					try {
						xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e) {
						alert("您的浏览器不支持AJAX!");
						return false;
					}
				}
			}
			return xmlHttp;
		}
		 
		// ajax post请求:
		function ajaxPost ( url , data , fnSucceed , fnFail , fnLoading ) {
			
			var param ={
				data:data,
				action:'my_action'
			}
			var ajax = ajaxObject();
			ajax.open( "post" , url , true );
			ajax.setRequestHeader( "Content-Type" , "application/json" );
			ajax.onreadystatechange = function () {
				if( ajax.readyState == 4 ) {
					if( ajax.status == 200 ) {
						fnSucceed( ajax.responseText );
					}
					else {
						fnFail( "HTTP请求错误!错误码:"+ajax.status );
					}
				}
				else {
					fnLoading();
				}
			}
			ajax.send( param );
		 
		}
回到顶部