Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8383915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:17:14+00:00 2026-06-09T17:17:14+00:00

Building my first webapp with jQuery Mobile – this will need to work with

  • 0

Building my first webapp with jQuery Mobile – this will need to work with PhoneGap eventually so I’m trying to keep it simple. Problem is I’m trying to load remote content from a webserver using $.ajax and I’m not getting a response.

Code (slightly truncated for ease of reading)

<!DOCTYPE html>
<html>
<head>
<title>App</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=no,target-densitydpi=device-dpi;" />

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>     
<link rel="stylesheet" href="scripts/jquery.mobile-1.1.1.min.css" />
<link rel="stylesheet" href="themes/apptheme.min.css" />
<link rel="stylesheet" href="styles/mobilestyle.css" type="text/css" media="screen" />
<link rel="stylesheet" href="styles/mobilesitetyle.css" type="text/css" media="screen" />
<script src="scripts/jquery-1.7.1.min.js"></script>
<script src="scripts/jquery.mobile-1.1.1.min.js"></script>
<script src="scripts/jquery.url.js"></script>

<script type="text/javascript">
    $(document).bind("pagebeforechange", function (e, data) {
        // We only want to handle changePage() calls where the caller is
        // asking us to load a page by URL.

        if (typeof data.toPage === "string") {
            // We are being asked to load a page by URL, but we only
            // want to handle URLs that request the data for a specific
            // category.

            var u = $.mobile.path.parseUrl(data.toPage);

            var re = /^#productList/;
            if (u.hash.search(re) !== -1) {
                $.ajax({
                    url: "http://myproductwebsite/products.aspx",
                    datatype: "html",
                    success: function (data) {
                        $('.submenu').html(data);
                        alert('Load was performed.');
                    }
                });
            }

        }
    });

</script>
</head>
<body>
<div style="width:100%;font-size:13px;" data-role="page" id="home">
    <div data-role="header" data-position="fixed">          
        <h1>Home</h1>            
    </div>
    <div data-role="content" class="submenu">
        <a href="#productList" data-transition="slide"><img src="images/Icon-Products.png" alt="products" /></a>                
    </div>
    <div data-role="footer" class="ui-bar" data-position="fixed" data-theme="b"></div>
</div>

<div data-role="page" data-theme="a" id="productList" data-add-back-btn="true">
    <div data-role="header" data-position="fixed">          
        <h1>Products</h1>            
    </div><!-- /header -->
    <div data-role="content" class="submenu">product content    
        <!-- content gets put in here -->
    </div><!-- /content -->
    <div data-role="footer" class="ui-bar" data-position="fixed" data-theme="b"></div>
</div><!-- /page -->
</body>
</html>

Basically, passing a link with a hash, picking it up and trying to load content in from a remote webserver. This is the bit that doesn’t show any content – I can confirm that the url I’m using definitely displays HTML, so I should be able to pick it up and inject it.

The alert in the success event doesn’t fire, but if I put alerts either side of the ajax code they fire ok so it’s just passing through the middle.

I’ve had success with this code using .load() on a localhost setup but as soon as I’ve moved the content data out remotely and switched to ajax it has stopped working. Is there a way to do this with .load()? I liked the way you can just request a div out of the response with that.

Am I missing something simple? The content from the server will just be simple HTML pages of content from a CMS system.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:17:15+00:00Added an answer on June 9, 2026 at 5:17 pm

    I’ve done a bit of digging and found that it’s now possible to allow Cross-Domain scripting via ajax in modern browsers. I’ve added the following code to my index.html as in the initial question above:

    $(document).bind("mobileinit", function () {
            $.mobile.allowCrossDomainPages = true;
            $.support.cors = true;
        });
    

    This switches on support for the request. On the server side you need to return headers enabling it from that side too, which means you can lock it to a single page if you need to (.Net example):

    Response.AppendHeader("Access-Control-Allow-Origin", "*");
    

    I can now use the app from localhost and pull the content in from the remote server. It also works on phones. Will have to test with PhoneGap but from what I’ve read it does support it.

    Resources for this answer:

    https://forum.jquery.com/topic/cross-domain-requests-with-support-cors-and-mobile-allowcrossdomainpages

    http://enable-cors.org/#how-php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a mobile webapp with jquery mobile. Now let me first sketch
I'm building my first jquery mobile site and have run into a problem. When
I am building a mobile webapp with jquery mobile. Now what I want 2
This is my first foray into building a secure web application. It will be
I've been building my first Rails app and now I'm trying to deploy it,
I'm building my first ASP.NET MVC website, and I'm trying to figure out how
I'm building a webapp using the Zend Framework , and I need to model
I'm building a mobile interface with JQuery Mobile for an already existing web app
I'm building an AJAX webapp that will be hosted on Amazon EC2 at webapp.site.com.
I am building a web app with jquery mobile. On one page I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.