The Ajax response is not showing up within the success function in jQuery Mobile

Recently, I have been working on creating a simple login form with username and password fields using jQuery Mobile. The validation for the username and password is supposed to be done through an ajax page. Surprisingly, everything was working perfectly fine in my system - I was able to receive responses without any issues. However, when I tried converting my code into a .apk file using PhoneGap and running it on my mobile, I encountered an issue. It seems like my mobile is unable to receive any response from the ajax page. Strangely, instead of executing the code inside the success function, it directly moves to the error function. Can anyone point out what could possibly be going wrong here?

    $(document).on('pagebeforeshow', '#login', function(){
        $(document).on('click', '#submit', function() {
        if($('#username').val().length > 0 && $('#password').val().length > 0){
            $.ajax({
                url : 'liveurl/check.php',
                data: {action : 'login', formData : $('#check-user').serialize()}, 
                type: 'post',
                beforeSend: function() {
                     $.mobile.loading(true);                 },
                complete: function() {
                     $.mobile.loading(false); 
                },
                success: function (result) {
                   if(result.status == "success"){  
                        resultObject.formSubmitionResult = result.uname;
                        localStorage["login_details"] = window.JSON.stringify(result);
                        $.mobile.changePage("#second");
                }else{
                        $.mobile.changePage("#login");
                        alert("incorrect login");           
                }
                    },
                    error: function (request,error) {
                        alert(error);    
                    }
                });                   
        } else {
            alert('Fill all necessary fields');
        }           
            return false;
        });
});

Answer №1

Here are a couple of key points to consider:

  1. The APK you are using is not connecting to your server properly. Make sure that the URL is correct, such as:

url: ""

  1. Ensure that all external URLs are whitelisted by referring to the documentation:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JavaScript - Automatic memory management following the execution of functions

After doing some research on garbage collection in JavaScript, I came across information stating that local variables of functions are collected once the function has returned (except for cyclical references which require breaking circles for the GC to fun ...

Failure to Fetch the Uploaded File's Value Using the Parameter

Objective: My aim is to automatically upload the second input named "file2" to the action result using jQuery code that is compatible with the latest versions of Firefox, Chrome, and Internet Explorer. Issue: The problem arises when HttpPostedFileBase ...

What might be the MongoDB counterpart to this SQL query?

select _id from project where projectName = '***' order by viewCount desc limit 5 Being relatively new to working with mongoose and having a decent grasp on SQL, I've tried my hand at retrieving the ObjectId of the sorted results. ProjectM ...

Issue with updating Angular list reference when deleting an item

My current task involves implementing a feature that displays selected items from a hierarchical structure on the right side. slice.component.ts : import { Component, Input, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core&a ...

Begin loading your script file at the conclusion of the content load in AngularJS

I have implemented the script below: $rootScope.$on('$includeContentLoaded', function (eve,uri) { var js = document.createElement("script"); js.type = "text/javascript"; js.src = '/assets/js/scripts.js'; ...

Implementing Event Listeners in Vue 3.0: A Guide to Attaching to the Parent Element

How can I attach an addEventListener to the parent element in Vue 3.x? I discovered that you can access the parent by using this code: import { getCurrentInstance, onMounted } from 'vue' onMounted(() => { console.log(getCurrentInstance() ...

What is the process for transferring a web project to my local server?

I'm having trouble figuring out how to connect my web application to the server. I attempted to use the following code: res.sendFile(path.resolve('./public/index.html')); However, it seems to be not linking the components that are written i ...

View the HTML output in a Rails Ajax Call

For debugging purposes, I am trying to view the HTML response when making an AJAX request. Currently, when I check the response, I see tags like: <li>something</li> What I actually want is: Something I do not want to see the tags, just the ...

Using PHP to query an array and sending the results to the client-side using

I am relatively new to utilizing jQuery and AJAX, so I've encountered a minor issue. I'm aiming to incorporate PHP query results into my jQuery code but I seem to be struggling with the implementation. Here is the snippet of code I am using to in ...

Efficient Error Handling in Next.JS with Apollo GraphQL Client

Although the component successfully renders the error state, an uncaught exception is displayed in the console and a dialogue box appears in the browser. How can expected errors be handled to prevent this behavior? import { useMutation, gql } from "@a ...

Oops! Make sure to explicitly allow the dependency @types/html2canvas by adding it to the "allowedNonPeerDependencies" option

After installing the html2canvas package in my Angular library project, I encountered an error when compiling in production mode using the command ng build --prod. The specific error message is as follows: ERROR: Dependency @types/html2canvas must be exp ...

I always seem to encounter the issue of receiving a NULL response in PHP when attempting to send variables through AJAX. What could be

I've been struggling to pass JSON data from JavaScript using AJAX to a PHP file. Despite trying numerous solutions found online, none of them seem to be effective. Here is an excerpt from my JavaScript file (a.html): <html> <head&g ...

Step-by-step guide on eliminating the modal post-validation

Newbie in reactjs looking for help with modal validation issue. Goal: Press submit button inside modal, validate, then close the modal. Want to reuse modal for another row. Problem: I'm having trouble making the function work for a new row after ...

Encountering an issue with Angular build in Docker: [ERR_STREAM_DESTROYED] - Write function cannot be called after a stream

Below is the docker file I'm using to build my Angular project: FROM node:12-buster-slim as build-step RUN mkdir -p /app COPY . /app WORKDIR /app RUN chmod 777 -R /app RUN npm install ARG configuration=production RUN npm run build -- --output-path=./ ...

Once the image has been observed, what steps can be taken to close it?

I wish to implement a functionality where clicking on the view button will enlarge the image, and another click on the page will return it to its original size. import * as React from 'react'; import Box from '@mui/material/Box'; imp ...

Matching the heights of div-containers within cards

Is there a way to ensure that the containers within my cards are all the same height? I'm not referring to the actual cards themselves, but rather the elements inside them. This is what my code currently looks like: .card-text { border: 1px solid ...

Exploring the seamless integration of AngularJs databinding with JSON for dynamic content

I have a question that seems simple, but I can't seem to find the answer anywhere. My goal is to load JSON data from my server into the client using AngularJS. How can I display all three slides in my view with AngularJS? Currently, with this code, ...

Issue with onClick event not firing when using option tag in React

onClick event seems to have an issue with the <option> tag. How can we successfully use the onClick event with the select option tags while assigning different parameters to each option? async function setLanguage(language) { ...

Difficulty Parsing Date within XLSX File Using SheetJs

When attempting to read an XLSX file using the sheetjs node-module, I encountered a problem with dates in one of the columns. The original data in the file is formatted as '2/17/2020', but after parsing it through xlsx, the format changes to &apo ...

ng-disabled with function that activates on change

I am attempting to create a submit validation button that will only enable when all fields have been entered correctly. Due to the complexity of the validation process, I am unable to rely solely on formName.$invalid and need to write a custom function for ...