I have created a hook that sits at the bottom of the page and calls a asp.net webservice and returns an email address. But it also appends &securitytoken=guest to my payload that i send, how do i get it not to send this data as it produces a json error.? and fails the request.
Remove &securitytoken=guest from Ajax call
Collapse
X
-
Tags: None
-
Do you own or have access to the source code of the webservice? If so, you can probably fix it on its end. I would fix there if possible.
If not, then consider this fix on vB side by adding this script in your hook:
Code:$.ajaxPrefilter(function (options, originalOptions, xhr) { //if ajax request is for external domain, remove securitytoken parameter if (options.url.indexOf(document.domain) === -1) { if (options.data) { //remove from GET data var qs = vBulletin.parseQueryString('?' + options.data), newData = []; delete qs.securitytoken; //options.data is URL-encoded so we cannot use $.param() to transform back to querystring format //otherwise, it will be double URL-encoded $.each(qs, function(key, value) { newData.push(key + '=' + value); }); options.data = newData.join('&'); if (typeof options.formData !== 'undefined' && $.isArray(options.formData)) { $.each(options.formData, function(index, obj) { if (obj.name === 'securitytoken') { options.formData.splice(0, 1, obj); return false; } }); } } else if (window.FormData && options.data instanceof FormData) { //remove from POST data options.data.delete('securitytoken'); } } });
This is untested. Please let me know if this works or not.👍 1-
Related, I just added a JIRA to skip auto-adding the vB security token to external requests: http://tracker.vbulletin.com/browse/VBV-15262
-
-
Thanks for the code. Should I put this after my script or ? . This is my script
Code:$(function () { $('#regDataEmail').on('blur', function () { var name = $(this).val(); var obj = { email: name }; $.ajax({ type: "POST", url: "https://www.somedomain.co.uk/forum-email-service/CheckEmail.asmx/ReturnUserEmail", data: '{email:' + JSON.stringify(obj) + '}', contentType: "application/json; charset=utf-8", }).done(function (data) { console.log(JSON.parse(data.d)); }).fail(function (jqHXR, textstatus, error) { console.log(jqHXR); }); }); });
Comment
-
I put the code in front of the function and it returned with an '=' on the end
{email:{"email":"[email protected]"}}=
-
-
Ok, try this one:
Code:$.ajaxPrefilter(function (options, originalOptions, xhr) { //if ajax request is for external domain, remove securitytoken parameter if (options.crossDomain) { if (options.data) { //remove from ajax data if (options.contentType.indexOf('json') !== -1) { options.data = options.data.replace(/&securitytoken=.*/, ''); } else { var qs = vBulletin.parseQueryString('?' + options.data), newData = []; delete qs.securitytoken; //options.data is URL-encoded so we cannot use $.param() to transform back to querystring format //otherwise, it will be double URL-encoded $.each(qs, function(key, value) { newData.push(key + '=' + value); }); options.data = newData.join('&'); if (typeof options.formData !== 'undefined' && $.isArray(options.formData)) { $.each(options.formData, function(index, obj) { if (obj.name === 'securitytoken') { options.formData.splice(0, 1, obj); return false; } }); } } } else if (window.FormData && options.data instanceof FormData) { //remove from POST data options.data.delete('securitytoken'); } } });
Code:"{email:{"email":"[email protected]"}}[COLOR=#FF0000]&securitytoken=1444423832-3aeffb8c560568e5c678e182c8d24d819177893e[/COLOR]"
Comment
-
-
Related Topics
Collapse
-
by hienntpHello,
I have another one and I need your help.
I created a mode for my forum (vb5). I used ajax to transfer data from outside to core/packages/helloworld/api/page.php
PHP Code:<?php
-
Channel: Support Issues & Questions
Wed 19 Aug '15, 5:36pm -
-
by tomasdWe run vB5 on nginx. Cron jobs don't work - javascript returns an error, upon further inspection the reason is that running this url directly: ajax/apidetach/cron/run, it returns ""Invalid AJAX...
-
Channel: Support Issues & Questions
Tue 23 Jun '15, 5:08am -
-
can i one tell me how to How to Turn of AJAX Paging in Thread View
example page i want to turn off ajax http://www.fropki.info/forum/fropki-...a-model-you-sh...-
Channel: Support Issues & Questions
Thu 21 Apr '16, 9:45pm -
Comment