2

The given code loads html content in desktop browsers.

But the same is not working in mobile browser(android - chrome).

$(document).ready(function() {
 loadDiv();
});

loadDiv() { 
$("#divId").load(url); 
}

How can i do this ?

Sulthan Allaudeen
  • 11,330
  • 12
  • 48
  • 63
user3151113
  • 41
  • 1
  • 4
  • where is url variable declaration? – RGS Mar 26 '14 at 12:54
  • 1
    Does the page have any errors on it that may cause the jQuery to not execute properly? The following post shows how to view the console log in Chrome on Android (if you're using Android OS) http://stackoverflow.com/questions/2314886/how-can-i-debug-javascript-on-android – NuNn DaDdY Mar 26 '14 at 12:56
  • I have to agree with @RGS. Shouldn't it read ```var loadDiv = function() {/*...*/}```? Or simply put ```$("#divId").load(url);``` inside ```$(document).ready(function() {/*...*/})``` (which btw. can be shortened to ```$(function() {/*...*/})```). – flu Mar 26 '14 at 12:56
  • url is declared inside lodDiv() method. it's working fine in desktop browsers. i have added alerts before and after the load() method and that also working fine. – user3151113 Mar 26 '14 at 13:03
  • Is that your exact code? Because that is not how you declare a function, it's invalid syntax – CodingIntrigue Mar 26 '14 at 13:34

1 Answers1

0

It is definetly about your url variable.

You cannot load the source from external web sites.It must be under your domain.

So if i were you.I'd add some basic html under my domain.

Let me explain;

Let say you have an index folder.And index.html inside of it.Add example.html to this folder. So far you folder details should like that

  • index.html --> it has script tags which calls your functions etc..

  • script.js --> this has your jquery functions

  • example.html--> add some p tags or anything

And now:

$document.ready(function(){
   var url = "example.html";
   $("#divId").load(url); 
});

If it works then you know its all about your url variable.

user54539
  • 35
  • 6