【问题标题】:CasperJS - The proper way to send AJAX request and handle themCasperJS - 发送 AJAX 请求并处理它们的正确方法
【发布时间】:2016-09-19 12:10:07
【问题描述】:

在试图弄清楚为什么我不能使用 CasperJS 发送 AJAX 请求后,我感到很沮丧。我已经按照官方文档,试图弄清楚自己,但没有运气。

我的应用程序需要向服务器发送一个包含 2 个图像名称的数组的 AJAX,结果必须是一个字符串。

这是我的尝试之一,我将不胜感激。

// idx is the index number of current picture. The images without extension as they are processed on server side
function getCalcResult()
{
	return JSON.parse(__utils__.sendAJAX('http://localhost:8081', 'GET', {'img1': 'screenshot' + idx, 'img2': 'Expected_' + idx}, false));
}

【问题讨论】:

  • 我想我知道问题出在哪里,但您应该展示一个更大的代码示例以确保。请edit您的问题相应。看来你还没有阅读足够的文档。

标签: javascript ajax get automation casperjs


【解决方案1】:

你试过评估吗?

function getCalcResult()
{
  return JSON.parse( 
        casper.evaluate(function(){
          return __utils__.sendAJAX('http://localhost:8081', 'GET', {'img1': 'screenshot' + idx, 'img2': 'Expected_' + idx}, false);
        }
    );
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-24
    相关资源
    最近更新 更多