多个AJAX请求使用时

时间:2016-07-26 22:59:34

标签: jquery ajax .when

一个AJAX请求可以正常工作,但是当我添加第二个AJAX请求时,它没有。

工作代码(按预期返回'wins:3')

26-Jul-2016 18:46:28    :compileGroovy UP-TO-DATE
26-Jul-2016 18:46:28    :buildProperties UP-TO-DATE
26-Jul-2016 18:46:28    :processResources UP-TO-DATE
26-Jul-2016 18:46:28    :classes UP-TO-DATE
26-Jul-2016 18:46:28    :compileTestJava UP-TO-DATE
26-Jul-2016 18:46:28    :compileTestGroovy UP-TO-DATE
26-Jul-2016 18:46:28    :compileGsonViews UP-TO-DATE
26-Jul-2016 18:46:36    :war
26-Jul-2016 18:46:44    Could not transfer artifact com.company.software:app-name:war:16.7.26-RELEASE from/to remote (https://www.company.com/nexus/repository/maven-releases/): Failed to transfer file: https://www.company.com/nexus/repository/maven-releases/com/company/software/app-name/16.7.26-RELEASE/app-name-16.7.26-RELEASE.war. Return code is: 400, ReasonPhrase: Repository does not allow updating assets: maven-releases.
26-Jul-2016 18:46:44    Could not transfer artifact com.company.software:app-name:pom:16.7.26-RELEASE from/to remote (https://www.company.com/nexus/repository/maven-releases/): Failed to transfer file: https://www.company.com/nexus/repository/maven-releases/com/company/software/app-name/16.7.26-RELEASE/app-name-16.7.26-RELEASE.pom. Return code is: 400, ReasonPhrase: Repository does not allow updating assets: maven-releases.
26-Jul-2016 18:46:44    :uploadArchives FAILED
26-Jul-2016 18:46:44    
26-Jul-2016 18:46:44    FAILURE: Build failed with an exception.
26-Jul-2016 18:46:44    
26-Jul-2016 18:46:44    * What went wrong:
26-Jul-2016 18:46:44    Execution failed for task ':uploadArchives'.
26-Jul-2016 18:46:44    > Could not publish configuration 'archives'
26-Jul-2016 18:46:44       > Failed to deploy artifacts: Could not transfer artifact com.company.software:app-name:war:16.7.26-RELEASE from/to remote (https://www.company.com/nexus/repository/maven-releases/): Failed to transfer file: https://www.company.com/nexus/repository/maven-releases/com/company/software/app-name/16.7.26-RELEASE/app-name-16.7.26-RELEASE.war. Return code is: 400, ReasonPhrase: Repository does not allow updating assets: maven-releases.
26-Jul-2016 18:46:44    
26-Jul-2016 18:46:44    * Try:
26-Jul-2016 18:46:44    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
26-Jul-2016 18:46:44    
26-Jul-2016 18:46:44    BUILD FAILED
26-Jul-2016 18:46:44    
26-Jul-2016 18:46:44    Total time: 27.993 secs

而这不是,变量现在是未定义的('wins:undefined'):

function GetMissingData(data, myID)
{
	$.when(AJAXf1(myID, '4')).done(
		function(a1)
		{
			console.log("wins: "+a1[0].DATA);
		}
	);
  }

function AJAXf1(myID, val)
{
	return $.ajax({   
		url: "./PHP/ajaxRequests.php",   
		dataType: "json",
		data : 
			{
				'moreData' : myID,
				'res' : val
			}
	})
}

(是的,我正在调用相同的函数,我正在测试。将来,我将更改函数的一个参数)

由于

1 个答案:

答案 0 :(得分:1)

在第一个示例中,您直接将ajax响应作为单个JS对象。 在第二个中你有一个JS对象数组(类似 [Object," success",Object] )。而且我认为你不能在不同的结构上使用相同的代码。