jakerella / jquery-mockjax

The jQuery Mockjax Plugin provides a simple and extremely flexible interface for mocking or simulating ajax requests and responses
Other
2.12k stars 376 forks source link

Same URL but REQUEST Type multiple not working. #329

Closed vinothwindows47 closed 6 years ago

vinothwindows47 commented 6 years ago
$.mockjax({
    url: '/*/portal/hcl/api/v1/projects',
    proxyType: "GET",
    proxy: "mocks/projects/list.json"
});
$.mockjax({
    url: '/*/portal/hcl/api/v1/projects',
    proxyType: "POST",
    proxy: "mocks/projects/create.json"
});

When I use post "/projects" URL , always proxy takes "mocks/projects/list.json" files. What can I do for it . @bantic @neonux @mlynch @kesselborn @malsup

jakerella commented 6 years ago

The proxyType refers to how the proxy file will be retrieved, NOT how the mock will be matched. Your two mockjax handlers are for the same request. I think what you probably want is just type, the default for how to retrieve the proxy file is "GET"... which is almost always what you want. Change your code to this:

$.mockjax({
    url: '/*/portal/hcl/api/v1/projects',
    type: "GET",
    proxy: "mocks/projects/list.json"
});
$.mockjax({
    url: '/*/portal/hcl/api/v1/projects',
    type: "POST",
    proxy: "mocks/projects/create.json"
});
vinothwindows47 commented 6 years ago

Thank you very much

vinothwindows47 commented 6 years ago

@jakerella

How do you pass parameter in URL ?

URL : /*/portal/hcl/api/v1/projects?type=git&page=1

$.mockjax({ url: '/*/portal/hcl/api/v1/projects', urlParams: ["type", "page"], type: "GET", proxy: "mocks/projects/list.json" });

jakerella commented 6 years ago

Just like you have it. This seems to be a different issue, so I'm going to close this issue. If you have questions you may want to try StackOverflow, but if you find a bug please post again!