mockjax

No response with jquery-mockjax

家住魔仙堡 提交于 2019-12-11 11:07:50
问题 I am trying to use jquery-mockjax library to mock ajax, but I cannot see any response. My code is as follow : <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="components/jquery/jquery.js"></script> <script src="components/jquery-mockjax/jquery.mockjax.js"></script> <script> $(function(){ $.mockjax({ url: '/test/inline', contentType: "text/json", responseTime: 0, responseText: { say: 'Hello world!' } }); $('#btn').click(function(){ $.ajax({

Why does mockjax return an altered response to my Ajax consumer?

别说谁变了你拦得住时间么 提交于 2019-12-08 09:31:40
问题 I'm using mockjax to simulate an Ajax call, but I'm experiencing that the data received by my Ajax callback is different from what I pass to mockjax (via the 'responseText' parameter). In this example, I've chosen the response to be '14.0', but the callback receives '14' instead: $.mockjax({ url: "/test", contentType: "text/json", responseText: "14.0" }); $.ajax({ url: "/test", datatype: "json" }).done(function(data) { alert(data); });​ Why is it that the received data is different from what

QUnit: How to test ajax call without modifying the ajax call

荒凉一梦 提交于 2019-12-03 13:27:58
问题 How can I write a QUnit test for this: function doSomethingWithAjax() { $.ajax({ url: '/GetHelloWorld', success: function(data) { $("#responseFromServer").text(data); }, }); } Mockjax+qunit requires a start() call in the ajax complete() method. 回答1: test("should mock ajax", function() { $.ajax = function(options) { equals(options.url, "/GetHelloWorld"); options.success("Hello"); }; doSomethingWithAjax(); equal($("#responseFromServer").text(), "Hello"); }); 回答2: The jasmine-ajax library allows

QUnit: How to test ajax call without modifying the ajax call

你说的曾经没有我的故事 提交于 2019-12-03 02:51:16
How can I write a QUnit test for this: function doSomethingWithAjax() { $.ajax({ url: '/GetHelloWorld', success: function(data) { $("#responseFromServer").text(data); }, }); } Mockjax+qunit requires a start() call in the ajax complete() method. test("should mock ajax", function() { $.ajax = function(options) { equals(options.url, "/GetHelloWorld"); options.success("Hello"); }; doSomethingWithAjax(); equal($("#responseFromServer").text(), "Hello"); }); The jasmine-ajax library allows you to define mock responses for all ajax calls without touching the calls themselves. This question has a few

How to test if an employee is connected via VPN with client-side JavaScript

送分小仙女□ 提交于 2019-12-02 06:42:13
问题 There are employees that will visit the external site to see a link to an internally hosted site. We only want the link to show if they have VPN'd into the network. How, with JavaScript, can I test the availability of something that isn't online externally. I have attempted to use a .JS file but it can get cached and seem available when it really isn't. Same with an image. Maybe JSONP with MockJax to avoid cross-site scripting errors? 回答1: On the intranet site make a JS file that will either