Skip to content
This repository
Browse code

Fix for issue 1580 - phonegap: Pages with data-ajax="false" on form f…

…ail to load

In the $.ajax() callback, we look for elements with @href, @src, and @data-ajax="false" elements, the code then assumes that matching elements will have either @href or @src, which of course forms don't ... they have @action ... so the code throws an exception because thisUrl is undefined.

- I reworked the code to handle action and check to make sure we have an attribute and url string before attempting to use them.
  • Loading branch information...
commit e597ccb381913308ce4c31662c8eba67509f8c1a 1 parent e775f5e
Kin Blas authored May 06, 2011

Showing 1 changed file with 20 additions and 7 deletions. Show diff stats Hide diff stats

  1. 27  js/jquery.mobile.navigation.js
27  js/jquery.mobile.navigation.js
@@ -606,14 +606,27 @@
606 606
 					if( !$.support.dynamicBaseTag ) {
607 607
 						var newPath = path.get( fileUrl );
608 608
 						to.find( "[src], link[href], a[rel='external'], :jqmData(ajax='false'), a[target]" ).each( function() {
609  
-							var thisAttr = $( this ).is( "[href]" ) ? "href" : "src",
610  
-								thisUrl = $( this ).attr( thisAttr );
611  
-
612  
-							//if full path exists and is same, chop it - helps IE out
613  
-							thisUrl = thisUrl.replace( location.protocol + "//" + location.host + location.pathname, "" );
  609
+							var attrs = [ "href", "src", "action" ],
  610
+								thisAttr = undefined,
  611
+								thisUrl = undefined;
  612
+
  613
+							for (var i = 0; i < attrs.length; i++) {
  614
+								var a = attrs[i],
  615
+									v = $( this ).attr( a );
  616
+								if (v) {
  617
+									thisAttr = a;
  618
+									thisUrl = v;
  619
+									break;
  620
+								}
  621
+							}
614 622
 
615  
-							if( ! /^(\w+:|#|\/)/.test( thisUrl ) ) {
616  
-								$( this ).attr( thisAttr, newPath + thisUrl );
  623
+							if ( thisAttr && thisUrl ) {
  624
+								//if full path exists and is same, chop it - helps IE out
  625
+								thisUrl = thisUrl.replace( location.protocol + "//" + location.host + location.pathname, "" );
  626
+	
  627
+								if( ! /^(\w+:|#|\/)/.test( thisUrl ) ) {
  628
+									$( this ).attr( thisAttr, newPath + thisUrl );
  629
+								}
617 630
 							}
618 631
 						});
619 632
 					}

0 notes on commit e597ccb

Please sign in to comment.
Something went wrong with that request. Please try again.