Sending a form from an iPhone device to a PHP backend server

It seems like I'm overlooking a simple aspect... Here is a basic form that I want to submit to a PHP script. It works perfectly on PC and Mac, but it doesn't function properly in Safari on iPad, iPhone, etc. Do you think there's some mobile element that I might be missing?

<html>
<head>
    <title>Title</title>
    <script src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.js"></script>
    <script type="text/javascript">

$('form').submit(function(){
    var postData = $(this).serialize();

    $.ajax({
        type: 'POST',
        data: postData,
        url: "http://www.norwichandyork.com/pocketleads/utilities/accounts.php",
        success: function(data){
            console.log(data);
            alert('Your comment was successfully added');
        },
        error: function(){
            console.log(data);
            alert('There was an error adding your comment');
        }
    });

    return false;
});
</script>
</head>
<body>


<form method="post" action="http://www.norwichandyork.com/pocketleads/utilities/accounts.php">
    <label for="email">
        <b>Email</b>
        <input type="text" id="email" name="email">
    </label>

    <label for="fname">
        <b>fname</b>
        <input type="text" id="fname" name="fname">
    </label>

    <input type="submit" value="Save">
</form>

</body>
</html>

I've provided my full code again with the action URL included for easy testing. Thank you in advance for any assistance you can provide. :)

Answer №1

Resolved! I encountered an issue, not sure if it's related to Xcode or PhoneGap specifically. It turned out that whitelisting every domain accessed from the app was necessary for it to work properly. Even though my domain was already whitelisted, there was still an issue. Upon checking my compile error log, I stumbled upon this helpful resource: . By adding *.mydomain.com to the whitelist, all functionality is now working perfectly. Thank you to everyone who contributed their insight.

Answer №2

<script type="text/javascript">

rather than

<script language="JavaScript">

Answer №3

<form action="post">

The action attribute within the form element determines where the data will be sent. If your PHP script is not named "post", consider changing action to method and providing the correct action.

<script language="JavaScript">

Additionally, there is no need to specify the language attribute for the script element (as it is outdated). Before HTML5, use the type attribute with a value of text/javascript for JavaScript. In HTML5, all script elements are automatically assumed to be JavaScript unless stated otherwise.

Although you seem to be hijacking the form regardless, considering the information about action/method may still be beneficial. Therefore, I will keep this answer as is.

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

"Renaming a file to a custom name in React JS: A step-by-step guide for

Is there a way to custom name the downloaded PDF file when opening it in base64 format using window.open()? Currently, the PDF is being downloaded as "download.pdf" and I would like to specify a different name for the file. Thank you in advance. fetc ...

Gingerbread mechanism spilling the beans on handling ajax requests

Currently, I am in the process of developing a PhoneGap application that must be compatible with Android Gingerbread. Unfortunately, it seems that devices running on Gingerbread encounter issues when trying to make AJAX requests to our service API. Strange ...

Am I on the right track in my understanding of how document and viewport relate to mouse position in JavaScript?

After reviewing responses from a previous inquiry, it is evident that both pertain to the x and y coordinates of mouse positions. In relation to the document and In relation to the viewport. I have delved into an article on QuirksMode, yet I feel ther ...

Create a default function within a mongoose field

Is there a way to achieve the following in my code: var categorySchema = new Schema({ id: { unique: true, default: function() { //set the last item inserted id + 1 as the current value. } }, name: String }); Can this be done? ...

viewDidLoad concurrency problem

Currently, I am faced with the task of making a separate API call to retrieve JSON data for each movie that I wish to gather information about. To achieve this, I am attempting to iterate through an array of movie IDs and invoke the populateAssetObject met ...

What are the first steps for diving into Video-To-Texture rendering?

I am working with a video that has been downloaded and is stored as NSData*, with plans to convert it into a NSInputStream*. The specific file format is currently not important. My goal is to display this video onto a 3D object using a MTLTexture (or a s ...

Is it possible to achieve the full image when utilizing double buffering for drawing on canvas?

I have a code where I am using two canvas elements to draw an image in order to prevent flickering. However, I am facing an issue where I cannot get the full image to display when using this method. When I use just one canvas, the image displays fine. It ...

The page quickly displays the splash page only if the user is logged in

I implemented a user authentication system where certain pages are displayed based on whether the user is logged in or not. For instance, when accessing localhost:3000/ (the home page), it should either show the splash screen or the dashboard of the logged ...

Centering Objects on iOS Through Code

I have been working on updating an iPhone app to support the larger screen size of the 6 Plus. While all views are centered correctly on devices like the 5S or below, I have noticed that on the 6 Plus, they are slightly shifted to the left. How can I mod ...

Configuring multiple views directories in Express fails to function as expected

Looking to define multiple views directories in Express. Working with Express version 4.16.3, Node.js version v10.15, and EJS version 2.5.9. app.set('views', [path.join(__dirname, 'views'), path.join(__dirname, 'public/static/&apo ...

Interested in learning how to implement automatic data refreshing in real-time using React?

Exploring React by creating a basic Spotify app for the first time. Currently, the "Now playing" feature is triggered by a button click to display the user's current play. How can I make this update in real-time without the need for a button? <but ...

Ways to insert data in angularjs

As I attempt to add data to a list using the addGroup function, I encounter a type-error. The error message reads: "TypeError: Cannot read property 'push' of undefined" at r.$scope.addGroup (main.js:7) at fn (eval at compile (angular ...

retrieve room from a socket on socket.io

Is there a way to retrieve the rooms associated with a socket in socket.io version 1.4? I attempted to use this.socket.adapter.rooms, but encountered an error in the chrome console: Cannot read property 'rooms' of undefined Here is the method I ...

In Vue, props are not automatically assigned; be sure to avoid directly mutating a prop when assigning it manually to prevent errors

I am working with two Vue components: GetAnimal.vue and DisplayAnimal.vue. GetAnimal.vue sends a JSON object containing animal data to DisplayAnimal.vue using router push. DisplayAnimal.vue then displays this data. The process flow is as follows: I navigat ...

How to retrieve TypeScript object within a Bootstrap modal in Angular

Unable to make my modal access a JavaScript object in the controller to dynamically populate fields. Progress Made: Created a component displaying a list of "person" objects. Implemented a functionality to open a modal upon clicking a row in the list. ...

When the React js application is opened in a hosted environment, the CSS styling may be overridden

My React js application is hosted within another application. When a jQuery dialog opens, the React application also launches. While the functionality works correctly, some of the CSS styles are appearing incorrectly. I suspect that either the CSS from the ...

Changing a JavaScript Confirm to jQuery Confirm within a button element of an ASPX GridView

I am currently working on updating my code to replace the JavaScript confirm action with a Jquery confirm action. Using Jquery, I have implemented a Callback function that will run when the user clicks the OK button. How can I capture the OK action from t ...

Transforming a JSONP request to automatically parse a text response into JSON

If I have the following request $.ajax({ type: "GET", dataType: "jsonp", jsonp: "callback", jsonpCallback: "my_callback", url: my_https_url, headers:{"Content-Type":"text/html; charset=utf-8"}, success: function(data) { ...

Setting the vertices of a THREE JS geometry based on a specified angle

I have the desire to create a triangle with known angles (Alpha, Beta, Gamma) and side lengths (10). In order to draw a triangle, I must assign 3 vertices to the geometry with specific Vector3 values. Does THREE.js offer any tools or techniques suitable ...

Using API calls to update component state in React-Redux

I am currently working on setting up a React application where clicking on a map marker in one component triggers the re-rendering of another component on the page. This new component should display data retrieved from a database and update the URL accordi ...