找不到使用JQuery调用ajax后创建的元素

时间:2017-05-17 15:07:02

标签: javascript jquery html ajax

我正在创建一个JQuery UI对话框并在ajax调用中设置其html。其中一部分是form,其id设置为form。但是,当我尝试找到$.ajax({ type: "POST", url: lURL, data: lData, dataType: "json" }). done( function(response){ if ( response.success ){ lDialog = $("<div></div>").dialog( { height: "auto", maxHeight: 800, width: 750, autoOpen: false, buttons: [ { id: "saveBtn", text: "Save", icons: {primary: "ui-icon-check" }, click: function () { var lForm = lDialog.find("#" + formId); processFileActionSubmit(formId, lForm);//calls AjaxSubmit $(this).dialog("close"); } }, { id: "cancelBtn", text: "Cancel", icons: {primary: "ui-icon-close"}, click: function() { $(this).dialog("close"); } }], close: function (event, ui) { $(this).remove(); }, resizable: false, modal: true }); lDialog.html(response.content); }; lDialog.dialog("open"); }; }). fail( function(jqXHR, textStatus, errorThrown) { alert("Sorry, no info to display."); }); 时,它会失败。我知道这是因为元素是在解析初始DOM之后创建的,但是我如何刷新/访问这个元素(基本上我想使用jQuery Form Plugin提交表单)。

这是代码:

// Core
import { Injectable } from '@angular/core';
import { GoogleAuth, User } from '@ionic/cloud-angular';
import { LoadingController, Events } from 'ionic-angular';

// Plugins
import { Firebase } from '@ionic-native/firebase';


@Injectable()
export class GoogleAuthServices {
  userImg;
  profile_picture;
  fullName;
  pushToken;
  status;

  constructor(
    public googleAuth: GoogleAuth, 
    public user: User, 
    public loadingCtrl: LoadingController, 
    public events: Events
  ) {}

  signIn(): Promise<any>{
    let loading = this.loadingCtrl.create({
      content: 'Please wait...'
    });

    return this.googleAuth.login().then((userRes)=>{
        loading.present();
        alert(JSON.stringify(userRes));
        loading.dismiss();
    });
  }
}

感激地收到任何指示。

0 个答案:

没有答案