0

I am trying to verify if a cookie exists in jQuery mobile app before an ajax request gets sent in beforeSend event, but the line of code for doing this throws following exception: Uncaught TypeError: Object function (e,t){return new b.fn.init(e,t,r)} has no method 'cookie'.

My question: What is the right way to check if a cookie exists in jQuery mobile app Or this is not possible in current version of jQuery mobile? I am developing the hybrid mobile app in Icenium.

The code I am using is as below.

function CallGetEmployees() {
    var serviceurl = "http://localhost:49441/WebService1.asmx/GetEmployees";
    $.ajax({
        url: serviceurl,
        type: 'POST',
        async:true,
        cache:false,
        dataType:"json",
        beforeSend:  function(xhr, opts) {
            var formsCookie = $.cookie("cookie1");
            if (formsCookie == null) {
                xhr.abort();
                clearForm();
                setMode("login");
                $("#sessionEnded").html("Your session has ended. Please login again.");
                $("#sessionEnded").show();
            }
        }
Sunil
  • 20,653
  • 28
  • 112
  • 197
  • Are you using the jQuery cookie plugin? http://stackoverflow.com/questions/1458724/how-to-set-unset-cookie-with-jquery – EfrainReyes Dec 28 '13 at 17:14
  • No. I thought that plugin is not for mobile hybrid app. – Sunil Dec 28 '13 at 17:14
  • jQuery doesn't come out of the box with $.cookie, though. BTW, since you mention that you're doing a mobile hybrid app, are you using Phonegap? If so, according to this link: http://stackoverflow.com/questions/15349237/handling-cookies-in-phonegap-cordova you should use localstorage instead of cookies. – EfrainReyes Dec 28 '13 at 17:17
  • Ok. I am using Icenium. – Sunil Dec 28 '13 at 17:20
  • I see. Try testing your code with the jQuery.cookie plugin. – EfrainReyes Dec 28 '13 at 17:22
  • Ok. I will try. I know cookie is being set in hybrid app when I check in Fiddler, so cookies appear to be supported in hybrid app. – Sunil Dec 28 '13 at 17:24

0 Answers0